Python sets the key value of a key by changing its link

I wonder how to do something like this in python:

d = {'a': 3}
a_value_ref = d['a']
a_value_ref = 6
assert d['a'] == 6

I want to first compute a reference to a specific value in a layered dict, and then change it using this mechanism. Is it possible? Easy to use C / C ++. Thank you for your help.

+4
source share
2 answers

This is not how Python works, workarounds are not good solutions. I changed the way dict keys are accessed, and now I am updating the values ​​with the syntax dict[key] = value.

0
source

, , ( )

, , .

d = {'a': [3]}
a_value_ref = d['a']
a_value_ref[0] = 6
assert d['a'] == [6]
+2

Source: https://habr.com/ru/post/1672822/


All Articles