Oscar Benjamin wrote:
On Nov 7, 2012 5:41 AM, "Gregory Ewing" <greg.ew...@canterbury.ac.nz <mailto:greg.ew...@canterbury.ac.nz>> wrote:
 >
 > If anything is to be done in this area, it would be better
 > as an extension of list comprehensions, e.g.
 >
 >   [[None times 5] times 10]
 >
 > which would be equivalent to
 >
 >   [[None for _i in xrange(5)] for _j in xrange(10)]

I think you're right that the meaning of list-int multiplication can't/shouldn't be changed if this way.

A multidimensional list comprehension would be useful even for people who are using numpy as it's common to use a list comprehension to initialise a numpy array.

A more modest addition for the limited case described in this thread could be to use exponentiation:

 >>> [0] ** (2, 3)
[[0, 0, 0], [0, 0, 0]]

What would happen with

--> [{}] ** (2, 3)

or

--> [my_custom_container()] ** (2, 3)

?

~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to