Skip to content

Instantly share code, notes, and snippets.

@poros
Created October 4, 2015 16:16
Show Gist options
  • Save poros/6d0fdd5e98ad768b36e7 to your computer and use it in GitHub Desktop.
Save poros/6d0fdd5e98ad768b36e7 to your computer and use it in GitHub Desktop.
Overriding dictionaries
d = defaults.copy()
d.update(os.environ)
d.update(command_line_arguments)
# PYTHON3 ONLY!!!
from collections import ChainMap
d = ChainMap(command_line_arguments, os.environ, defaults)
# it's view, not a real dictionary. if you want something equivalent to a new one
d = ChainMap({}, command_line_arguments, os.environ, defaults)
# writes are done on the first map in the list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment