How to make arrays from Lists
bearophileHUGS at lycos.com
bearophileHUGS at lycos.com
Tue Nov 11 19:48:54 EST 2008
gc_ott:
> How do I change the value of any element to produce (say)
> [[99,0,0],[0,0,0],[0,0,0]] ?
>
> gordc
To create a 2D list, that is a list of lists:
x = [[0] * ncols for i in nrows]
(Don't do what you were doing, because you end with many references to
the same list, and that will give you troubles.)
To set an item you do just:
x[0][0] = 99
Bye,
bearophile
More information about the Python-list
mailing list