Skip to content

Instantly share code, notes, and snippets.

@treyhunner
Created February 20, 2016 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save treyhunner/2abe2617ea029504ef8e to your computer and use it in GitHub Desktop.
Save treyhunner/2abe2617ea029504ef8e to your computer and use it in GitHub Desktop.
Altering dictionary within ChainMap
>>> from collections import ChainMap
>>> user_context = {'name': "Trey", 'website': "http://treyhunner.com"}
>>> global_context = {'name': "Anonymous User", 'page_name': "Profile Page"}
>>> context = ChainMap({}, user_context, global_context)
>>> context['name']
'Trey'
>>> user_context['name'] = "Guido"
>>> context['name']
'Guido'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment