References and copies
me at privacy.net
Tue Jun 22 10:24:04 CEST 2004
"Larry Bates" <lbates at swamisoft.com> wrote in
news:ddqdnZ_PjrmN3krd4p2dnA at comcast.com:
> You might try:
> x=n*[n*[' ']]
> But I always question creating arrays this
> way in Python. It is normally much better
> to start with an empty list and build it as
> you go using .append() method.
Its just as well you question this as it creates a list containing n copies
of the same list.
A better way to write your example:
x = [ n*[' '] for i in range(n) ]
More information about the Python-list