Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Programming- This program should accept a list of one or more frozensets

ID: 3753400 • Letter: P

Question

Python Programming- This program should accept a list of one or more frozensets from the user in the console and provide correct output back to the user. Please provide properly structured code.

1) cartesianproduct: This function should accept a list of one or more sets or frozensets (you can convert between them using set(fxo st) and frozenset(st)). Its output is a set or frozenset encoding the ça tesian product; thus a list of two sets [ { 0 , i } , { 1 , 2 could give back (0,1),(0,2),(1,1),(1,2).In general, an input list of length N will yield a set of tuples of length N each.

Explanation / Answer

def cartesianproduct(sets): s1 = sets[0] s2 = sets[1] result = set() for n1 in s1: for n2 in s2: result.add((n1, n2)) return result print(cartesianproduct([{0, 1}, {1, 2}]))