[Python-ideas] Dict joining using + and +=

Dan Sommers 2QdxY4RzWzUUiLuE at potatochowder.com
Mon Mar 4 12:56:54 EST 2019


On 3/4/19 10:44 AM, Steven D'Aprano wrote:

 > If you know ahead of time which order you want, you can simply reverse
 > it:
 >
 >      # prefs = site_defaults + user_defaults + document_prefs
 >      prefs = dict(ChainMap(document_prefs, user_defaults, site_defaults))
 >
 > but that seems a little awkward to me, and reads backwards. I'm used to
 > thinking reading left-to-right, not right-to-left.

I read that as use document preferences first, then user
defaults, then site defautls, exactly as I'd explain the
functionality to someone else.

So maybe we're agreeing:  if you think in terms of updating
a dictionary of preferences, then maybe it reads backwards,
but if you think of implementing features, then adding
dictionaries of preferences reads backwards.


More information about the Python-ideas mailing list