Question

Implement in Python2. Develop the following python program. Implement Cartesian production of two sets. For example, y [1,3,7,9]

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def CartesianProduct(A,B):
    lst = []
    for x in A:
        t = []
        t.append(x)
        for y in B:
            temp = []
            for x in t:
                temp.append(x)
            temp.append(y)
            lst.append(temp)
    return lst

A = ['a','e']
B = [1,3,7,9]
print(CartesianProduct(A,B))

Output:

a, 1, [a, 3], [a, 7], [a, 9], [e, 1], [e,3], [e, 7], [e, 911 Process finished with exit code 0

Please up vote the solution if it helped. Thanks!

Add a comment
Know the answer?
Add Answer to:
Implement in Python 2. Develop the following python program. Implement Cartesian production of two sets. For...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • u are to write a program in Java that takes two sets of up to 5...

    u are to write a program in Java that takes two sets of up to 5 symbols(letters, numbers or any characters) and prints the cartesian product of the two sets. The program should allow the user to enter the characters for each set and the output should, consist of the name of each set followed by the characters and on the following line print the cartesian product. Example: {1,3,*} X {3,?,D} = {(1,3),(1,?),(1,D),(3,3),(3,?),(3,D,(*,3),(*,?),(*,D)} or {2,3,5,7} X (5,6} = {(2,5),(2,6),(3,5),(3,6),(5,5),(5,6),(7,5),(7,6)}

  • Subject: Management information technology (python) Write a program (script mode) that first sets x to a...

    Subject: Management information technology (python) Write a program (script mode) that first sets x to a string with the character 2, y to the value 3, and z to the value 23.3. Using the type function, the program must display the type of each of the following expressions: x y z y+z

  • write a java program that will perform the following. Given two finite sets, list all elements...

    write a java program that will perform the following. Given two finite sets, list all elements in the Cartesian product of these two sets. Given a finite set, list all elements of its power set.

  • PLEASE DO THIS IN PYTHON!!!!!!!! 1.) For each lab program you develop, make sure to include...

    PLEASE DO THIS IN PYTHON!!!!!!!! 1.) For each lab program you develop, make sure to include the following header - replace the dots with your section #, semester, your full name, your instructor’s name, and lab #:                         Class: CSE 1321L Section:       ...          Term:          ... Instructor:    ... Name:          ...    Lab#:          ... Make sure to put the correct comment character(s) before the above lines in each file. C# & Java use // for comments, Python uses a # Exercise #1:...

  • In Python 3, Implement a program that directs a cashier how to give change. The program...

    In Python 3, Implement a program that directs a cashier how to give change. The program has two inputs: the amount due and the amount received from the customer. Display the dollars, quarters, dimes, nickels, and pennies that the customer should receive in return. In order to avoid roundoff errors, the program user should supply both amounts in pennies, for example 526 instead of 5.26. Enter the amount due in pennies: 828 Enter the amount received from the customer in...

  • Write a Python program to implement Newton's method to estimate √12.

    Write a Python program to implement Newton's method to estimate √12.

  • In Python Develop a program that uses a list or dictionary that can be searched.   The...

    In Python Develop a program that uses a list or dictionary that can be searched.   The program should do some kind of processing of list or dictionary members.

  • Give a problem statement that requires you to develop a Python program that meets the following...

    Give a problem statement that requires you to develop a Python program that meets the following requirements (2 EC points) The program reads data from a text file and then assigns it to a string variable (2 EC points) The program defines and calls at least one function other than main() (2 EC points) The program uses a multi-way branch (if, followed by a number of elifs, followed by else) (2 EC points) The program uses a loop (for loop...

  • Program has to be in C# language Write a computer program that takes two sets (let...

    Program has to be in C# language Write a computer program that takes two sets (let the user determine the cardinality of each set and enter them manually) and calculates the following operations: Union Intersection Difference (set1 - set2) Cartesian product (set2 X set1) Check whether set2 is a subset of set1 or set1 is a subset of set2 Find the powerset of set1 and print out its elements and cardinality

  • PLEASE DO IN PYTHON Program 2: Design (pseudocode) and implement (source code) a program (name it...

    PLEASE DO IN PYTHON Program 2: Design (pseudocode) and implement (source code) a program (name it FeetMeters) to display a conversion tables for feet and meter as show below. Document your code and properly. Feet Meter 1.0 0.305 2.0 0.610 3.0 0.915 . . . . . . 19.0 5.7.95 20.0 6.100 Meter Feet 1.0 3.279 2.0 6.558 3.0 9.837 . . . . . . 19.0 62.301 20.0 65.574 The program defines the following methods: Method feetToMeter() converts from...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT