Suppose I have an list of lists:
lists = [
[1, 2, 5, 7],
[3, 6, 8, 10],
[2, 7, 9, 11]
]
I want to merge them (lowest to greatest index) if they have an intersecting value, while not copying the duplicate(s), so that the output looks like:
new_lists = [
[1, 2, 5, 7, 9, 11],
[3, 6, 8, 10],
]
I how can I manage this for large amount of lists, while being relatively eficient?