Concise idiom to initialize dictionaries

Gabriel Cooper gabriel.cooper at mediapulse.com
Wed Nov 10 20:31:32 CET 2004



Rainer Mansfeld wrote:

> Being a C/C++ programmer with only a couple of weeks of Python
> experience, I'd simply do:
>
> a = b = c = d = e = f = g = h = i = j = k = l = {}
>
> That's clear and compact, but is it 'pythonic'?

That notation would make each variable a reference to the same dictionary:

 >>> a = b = c = d = {}
 >>> a['test'] = 1
 >>> b
{'test': 1}
 >>>





More information about the Python-list mailing list