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

Gregory Ewing greg.ewing at canterbury.ac.nz
Wed Aug 3 04:29:19 EDT 2011


gc wrote:

> Alternatively, is there a version of iterable multiplication that
> creates new objects rather than just copying the reference?

You can use a list comprehension:

   a, b, c, d, e = [dict() for i in xrange(5)]

or a generator expression:

   a, b, c, d, e = (dict() for i in xrange(5))

-- 
Greg



More information about the Python-list mailing list