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

B

bahoo

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
 
I

irstas

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
 
7

7stud

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

list0 = [1]
list1 = [2,3,4,5]
list2 = [6,7,8]

allLists = [list0, list1, list2]
print allLists[1][3]
print allLists[0][0]
 
B

Bruno Desthuilliers

bahoo a écrit :
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?

listoflists = [
[1, 2, 3],
["foo", "bar", "baaz", "quux"],
["A", "B", "C", "D", "E"]
]

for alist in listoflists:
for item in alist:
print item
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top