Syntactic sugar for assignment statements: one value to multiple targets?

Katriel Cohn-Gordon katriel at katriel.co.uk
Wed Aug 3 04:36:19 EDT 2011


On Wed, Aug 3, 2011 at 9:25 AM, Steven D'Aprano <
steve+comp.lang.python at pearwood.info> wrote:

> gc wrote:
>
> > Target lists using comma separation are great, but they don't work
> > very well for this task. What I want is something like
> >
> > a,b,c,d,e = *dict()
>
> a, b, c, d, e = [dict() for i in range(5)]
>

I think this is good code -- if you want five different dicts, then you
should call dict five times. Otherwise Python will magically call your
expression more than once, which isn't very nice. And what if your datatype
constructor has side-effects?

Katriel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110803/5619e866/attachment-0001.html>


More information about the Python-list mailing list