Syntactic sugar for assignment statements: one value to multiple targets?
Zero Piraeus
schesis at gmail.com
Wed Aug 17 16:07:55 EDT 2011
:
Off on a tangent ...
On 16 August 2011 20:14, gc <gc1223 at gmail.com> wrote:
>
> Let me address one smell from my particular example, which may be the
> one you're noticing. If I needed fifty parallel collections I would
> not use separate variables; I've coded a ghastly defaultdefaultdict
> just for this purpose, which effectively permits what most people
> would express as defaultdict(defaultdict(list)) [not possible AFAIK
> with the existing defaultdict class].
Dunno if it's better than your ghastly defaultdefaultdict, but this works:
>>> from collections import defaultdict
>>> ddd = defaultdict(lambda: defaultdict(list))
>>> ddd["foo"]["bar"].append("something")
>>> ddd["foo"]["bar"]
['something']
>>>
-[]z.
More information about the Python-list
mailing list