Raz jeszcze - ciekawe propozycja, ale nadal ona nie rozwiązuje głównego problemu. Zobacz na kod poniżej: przy łączeniu połączonych wcześniej setów:
some_set = {"ref": {"a", "b"} }
some_set_2 = {"ref": {"d", "e"} }
some_set_3 = {"ref": {"h", "i"} }
some_set_4 = {"ref": {"q", "w"} }
ptr = {
'a': some_set,
'b': some_set,
'd': some_set_2,
'e': some_set_2,
'h': some_set_3,
'i': some_set_3,
'q': some_set_4,
'w': some_set_4,
}
some_set['ref'].update(
some_set_2['ref']
)
some_set_2['ref'] = some_set['ref']
some_set_3['ref'].update(
some_set_4['ref']
)
some_set_4['ref'] = some_set_3['ref']
some_set['ref'].update(
some_set_4['ref']
)
some_set_4['ref'] = some_set['ref']
for key, value in ptr.items():
print(key, value, id(value["ref"]))
# a {'ref': {'a', 'w', 'q', 'e', 'i', 'd', 'b', 'h'}} 2036214559912
# d {'ref': {'a', 'w', 'q', 'e', 'i', 'd', 'b', 'h'}} 2036214559912
# b {'ref': {'a', 'w', 'q', 'e', 'i', 'd', 'b', 'h'}} 2036214559912
# q {'ref': {'a', 'w', 'q', 'e', 'i', 'd', 'b', 'h'}} 2036214559912
# h {'ref': {'q', 'h', 'i', 'w'}} 2036214697768
# i {'ref': {'q', 'h', 'i', 'w'}} 2036214697768
# e {'ref': {'a', 'w', 'q', 'e', 'i', 'd', 'b', 'h'}} 2036214559912
# w {'ref': {'a', 'w', 'q', 'e', 'i', 'd', 'b', 'h'}} 2036214559912