Skip to content

Instantly share code, notes, and snippets.

@gregelin
Created May 18, 2021 10:51
Show Gist options
  • Save gregelin/a444088c0c5e2ebeb6cdfad65d200ca9 to your computer and use it in GitHub Desktop.
Save gregelin/a444088c0c5e2ebeb6cdfad65d200ca9 to your computer and use it in GitHub Desktop.
Python mind blowing updating obj by reference
>>> 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