I have a data structure like this
[
(123, 321),
(123, 456),
(999, 654),
(111, 456),
(999, 898),
(111, 654),
(481, 739),
]
How can I group the tuples together by any matching element? i.e. to get this result (order doesn't matter)
[
[(123, 321), (123, 456), (111, 456), (111, 654), (999, 654), (999, 898)],
[(481, 739)],
]
Here's another example:
input =
[
(123, 321),
(123, 456),
(111, 456),
(999, 898),
(481, 898),
(481, 549),
]
output =
[
[(123, 321), (123, 456), (111, 456)],
[(999, 898), (481, 898), (481, 549)],
]