Created
May 18, 2021 10:51
-
-
Save gregelin/a444088c0c5e2ebeb6cdfad65d200ca9 to your computer and use it in GitHub Desktop.
Python mind blowing updating obj by reference
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> list = [] | |
>>> obj = {"k1": {"ks1":"vs1"},"k2": {"ks2":list}} | |
>>> obj | |
{'k1': {'ks1': 'vs1'}, 'k2': {'ks2': []}} | |
>>> list.append({"ks3":"val"}) | |
>>> list | |
[{'ks3': 'val'}] | |
>>> obj | |
{'k1': {'ks1': 'vs1'}, 'k2': {'ks2': [{'ks3': 'val'}]}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment