I got two sets and want to add the differences to a list with a list comprehension.
Using one set works perfectly fine:
diff = [x for x in a.difference(b)]
However, when I try to include the second set (b) I get already a warning from PyCharm that the syntax is invalid.
Error message:
diff = [x,y for x in a.difference(b) for y in b.difference(a)]
^
SyntaxError: invalid syntax
Below is a web example and the comparative attempt with my input which creates lists within the diff
list which I do not want.
Web Example: my_list = [x * y for x in [20, 40, 60] for y in [2, 4, 6]]
diff = [[x,y] for x in a.difference(b) for y in b.difference(a)]
Output: [[9, 11], [9, 12], [5, 11], [5, 12]]
Expected Output: [5,9,11,12]
What is the syntax to create one list with the set differences from two sets?