Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to have a list of lists (or array of lists)

Reply
Thread Tools

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

 
 
bahoo
Guest
Posts: n/a
 
      04-03-2007
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

 
Reply With Quote
 
 
 
 
irstas@gmail.com
Guest
Posts: n/a
 
      04-03-2007
On Apr 3, 7:12 pm, "bahoo" <b83503...@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

 
Reply With Quote
 
 
 
 
7stud
Guest
Posts: n/a
 
      04-03-2007
On Apr 3, 10:12 am, "bahoo" <b83503...@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


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

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

 
Reply With Quote
 
Bruno Desthuilliers
Guest
Posts: n/a
 
      04-03-2007
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Numpy.array with dtype works on list of tuples not on list of lists? Alex van der Spek Python 2 09-18-2011 08:31 PM
common elements between list of lists and lists antar2 Python 2 07-17-2008 09:19 AM
list of lists of lists .... yomgui Python 6 07-31-2006 07:28 PM
List of lists of lists of lists... =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==?= Python 5 05-15-2006 11:47 AM



Advertisments