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

irstas at irstas at
Tue Apr 3 18:15:04 CEST 2007

On Apr 3, 7:12 pm, "bahoo" <b83503... at> 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,

More information about the Python-list mailing list