I'll explain with an example:
list_1 = [1, 2, 3]
list_2 = list_3 = list_1 # reference copy
print(magic_method(list_1))
# Should print ['list_1', 'list_2', 'list_3']
set_1 = {'a', 'b'}
print(magic_method(set_1))
# Should print ['set_1']
The requirement: return names of all variables pointing to the same reference. Is this at all possible with python?
I'm thinking something along the lines of iterating over globals()
and locals()
and equating id
s. Is there anything better?