Concise idiom to initialize dictionaries

Rainer Mansfeld MLists at romulo.de
Wed Nov 10 04:48:42 EST 2004


Frohnhofer, James wrote:
> The number of dictionaries I need is 12.  I started out with a dictionary of
> dictionaries, but my expressions (where I was actually using the dictionaries)
> were pushed over the readibility edge by the extra level of indirection.  I
> will probably stick with initializing them individually, preferring clear code
> to compact code (while always trying for both).

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'?

    Rainer




More information about the Python-list mailing list