proposition for syntax for initialisation of multidimensional lists
Batista, Facundo
FBatista at uniFON.com.ar
Tue Oct 12 17:07:04 EDT 2004
[Nils Grimsmo]
#- i always have trouble explaining why creation of
#- multidimensional lists
#- is not as straight forward as it could be in python. list
#- comprehensions
#- are ugly if you are new to the language. i really would like
#- to see it
#- made easy. i propose using tuples in the same way as
#- integers are now.
#- example:
#-
#- >>> [0] * (2,3,4)
#- [[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[0, 0, 0, 0],
#- [0, 0, 0,
#- 0], [0, 0, 0, 0]]]
You don't need list comprehensions::
>>> [[[0] * 4] * 3] * 2
[[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], [[0, 0, 0, 0], [0, 0, 0, 0],
[0, 0, 0, 0]]]
. Facundo
More information about the Python-list
mailing list