Concise idiom to initialize dictionaries

Fábio Mendes niels_bohr at uol.com.br
Tue Nov 9 23:52:53 CET 2004


> Perhaps you want a dict of dicts.
>     d = dict([(s, {}) for s in 'abc...z'])
> now refer to d['a'][key] instead of a[key]

Or even:
>>> a,b,c,d = [ {} for i in range(4) ]  

Fabio



More information about the Python-list mailing list