Let's say we have two lists of values, whereby each list only contains unique values unto itself. There will never be duplicate values in a single list.
L1 | L2
-------
a | a
b | d
c | e
d | g
e | h
f | i
| j
We can get the differences of these lists using set(L1).symmetric_difference(L2)
, but unfortunately that lumps the results together in a single list. For example, the output of list(set(L1).symmetric_difference(L2))
is ['c', 'b', 'h', 'i', 'j', 'f', 'g']
.
Is there a way to obtain two separate lists of output from list(set(L1).symmetric_difference(L2))
like ['c', 'b', 'f',]
and ['h', 'i', 'j', 'g']
instead?
Or is there a way to obtain two separate lists as output while comparing the two sets/lists against each other only once?
You can simply do the following:
And you can create a function to do that like this:
and then you call it like this:
Hope this helps.