I need to group sublists with the same elements together
For example:
list1 =[[1, 0], [2, 1], [30, 32]]
would link [1, 0]
and [2, 1]
together since they both contain 1
and those two would combine into [0, 1, 2]
So after linking, the new list should be like:
new_list1 = [[1, 0, 2], [30, 32]]
IE: there shouldn't be same number inside a sub-list and order is not important.
A longer example:
list2 = [[2, 3], [4, 3], [6, 5], [7, 6], [7, 8], [13, 14], [30, 32]]
after linking, it would be
new_list2 = [[2, 3, 4], [6, 5, 7, 8], [13, 14], [30, 32]]
So how can this be done in a general way?
See Question&Answers more detail:
os