I am not sure if this is possible in Python, but performance to my application is critical and I have the following scenario.
I am attempting merge two disjoint sets with the following implementation. I have a dictionary of sorted lists, where the keys in the dictionary point to the sorted list which holds the value (by reference). Like this
l1 = [1, 2, 3]
l2 = [4, 5, 6]
d = {1: l1, 2: l1, 3: l1, 4: l2, 5: l2, 6: l2}
Now I want to merge the two lists in place such that each key in the dictionary refers to the same underlying list like
l1 = l2 = l1 + l2
But this won't affect the references held within the dictionary, since a new list is created.
Speed is critical here, so I don't want to create new lists and reassign references to each key in the dictionary.
EDIT
I would expect the following code to run without an assertion error after this operation
for v in d:
assert d[v] is l1