[Tutor] Help me with two dimensional arrays in Python
Kent Johnson
kent37 at tds.net
Thu Oct 5 16:26:19 CEST 2006
Asrarahmed Kadri wrote:
> Its something very close.
> What I want is:
>
> 1
> 1 1
> 1 2 1
> 1 3 3 1
> 1 4 6 4 1
>
> This can be done using arrays, right or is there any other way??
Is this a homework assignment?
A list of lists seems like the appropriate way to represent this,
especially since it is not actually a square array.
Here is a simpler example that might give you some ideas:
In [5]: b=[]
In [6]: for i in range(5):
...: b.append(range(i))
...:
...:
In [7]: b
Out[7]: [[], [0], [0, 1], [0, 1, 2], [0, 1, 2, 3]]
Kent
More information about the Tutor
mailing list