Suppose you have input of the following format:
data = [(1, 5), (7, 2), (3, 4), (4, 8), (6, 3), (5, 2)]
I want to organize these numbers into a separate bucket or list.
If a number from a tuple is found inside another tuple then it means that those numbers should go into the same bucket; otherwise, into a different bucket.
For example, from the above example, the numbers will get distributed into two buckets:
bucket_a = {1, 5, 2, 7}
because of these tuples:
(1, 5)
(5, 2)
(7, 2)
and
bucket_b = {3, 4, 6, 8}
because of these tuples:
(3, 4)
(4, 8)