2D Arrays

Grzegorz Dostatni grzegorz at ugrad.cs.ualberta.ca
Sat Sep 9 14:45:22 EDT 2000


Try this:
>>> b=[]
>>> for x in range(0,5):
...     c=[]
...     for y in range(0,5):
...             c.append(y)
...     b.append(c)
... 
>>> b
[[0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0,
1, 2, 3, 4]]

Greg

########################################################################
Chemistry is physics without thought.
Mathematics is physics without purpose.

"If you want to know what God thinks about money, just look at the people
He gives it to." 
-- Old Irish Saying 

Time is the best teacher. Unfortunately, it kills all its students. 

On Sat, 9 Sep 2000, Jad Courbage wrote:

> Hi,
> 
> Could anybody tell me the command to build a 2D array ? (without using the
> NumPy module)
> 
> I tried something like :
> 
> for i in range(0,5):
>      for j in range(0,10):
>           arr[i][j]=i*j
> 
> but it doesn't work !
> Do i have to declare the array ?
> 
> Thanks.
> 
> 
> jad.
> 
> 
> 




More information about the Python-list mailing list