After Python 3.7, dictionaries are order-preserving. This allows us to get values as follows:
a = list(dict.values())[idx]
What I want to do is to set a value, which is nested as follows. There is an outer dictionary, its first value is an instance of a class. This class has another dictionary as attribute, and I would like to change the first value in this dictionary.
a = list(list(outer_dict.values())[0].dict_as_attribute.values())[0]
a = 1
How do I put the new a
back to its place? The above expression gives me a copy, and when I change a
, the one in the dictionary stays the same. Ofcourse, the following also doesn't work:
list(list(outer_dict.values())[0].attribute.values())[0] = a
Solutions using known keys or using different data structures don't help: I am not allowed to change the data structure and I also do not know the keys.
Thanks for the answers.