How to have a list of lists (or array of lists)

irstas at gmail.com irstas at gmail.com
Tue Apr 3 18:15:04 CEST 2007


On Apr 3, 7:12 pm, "bahoo" <b83503... at yahoo.com> wrote:
> Hi,
>
> I want to have many lists, such as list0, list1, list2, ..., each one
> holding different number of items.
> Is there something like
> list[0]
> list[1]
> list[2]
>
> so that I can iterate through this list of lists?
>
> Thanks!
> bahoo

listOfLists = [[1,2], [5,7,9], [4,2,1,4,6,6]]

No problem there. The lists can contain any objects, including lists.

for x in listOfLists:
    print 'list:',
    for y in x:
        print y,
    print




More information about the Python-list mailing list