![]() |
How to have a list of lists (or array of lists)
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 |
Re: How to have a list of lists (or array of lists)
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, |
Re: How to have a list of lists (or array of lists)
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] |
Re: How to have a list of lists (or array of lists)
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 |
| All times are GMT. The time now is 03:13 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.