Is it possible to specify the size of list at construction?
Michael Spencer
mahs at telcopartners.com
Tue Mar 1 15:56:14 EST 2005
Anthony Liu wrote:
> Yes, that's helpful. Thanks a lot.
>
> But what if I wanna construct an array of arrays like
> we do in C++ or Java:
>
> myArray [][]
>
> Basically, I want to do the following in Python:
>
> myArray[0][1] = list1
> myArray[1][2] = list2
> myArray[2][3] = list3
>
here you have to be careful to create N different lists. A list comprehension
provides a convenient way to do it:
myArray = [[] for i in range(N)]
More information about the Python-list
mailing list