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

Chris Angelico rosuav at gmail.com
Wed Aug 17 03:13:49 EDT 2011


On Wed, Aug 17, 2011 at 1:14 AM, gc <gc1223 at gmail.com> wrote:
> Perfectly reasonable request! Maybe there aren't as many cases when
> multiple variables need to be initialized to the same value as I think
> there are.
>

Minor clarification: You don't want to initialize them to the same
value, which you can do already:

a=b=c=d=e=dict()

You want to initialize them each to a fresh evaluation of the same
expression. What you're asking for is a syntax that writes an
expression once, but evaluates it many times; I think it's going to
work out something very similar to a list comprehension (as has been
mentioned).

ChrisA



More information about the Python-list mailing list