Re: For Loop in List

2013-01-13 Thread Mitya Sirenef
On 01/13/2013 07:45 AM, subhabangal...@gmail.com wrote: Dear Group, I have a list like, list1=[1,2,3,4,5,6,7,8,9,10,11,12] Now, if I want to take a slice of it, I can. It may be done in, list2=list1[:3] print list2 [1, 2, 3] If I want to iterate the list, I may do as, for i in list1:

Re: For Loop in List

2013-01-13 Thread Tim Chase
On 01/13/13 07:48, Boris FELD wrote: 2013/1/13 Tim Chase : SIZE = 3 for i in range(len(list1)//SICE): ... print list1[i*SIZE:i*SIZE+SIZE] A little shorter and simpler version: x = x[1:] for i in range(0,len(x),SIZE): ... print x[i: i+SIZE] Doh, I always forget that range() takes

Re: For Loop in List

2013-01-13 Thread Boris FELD
2013/1/13 Tim Chase : > On 01/13/13 06:45, subhabangal...@gmail.com wrote: > SIZE = 3 for i in range(len(list1)//SICE): > ... print list1[i*SIZE:i*SIZE+SIZE] > ... > [1, 2, 3] > [4, 5, 6] > [7, 8, 9] > [10, 11, 12] > A little shorter and simpler version: >>> x = x[1:] >>> for i in ra

Re: For Loop in List

2013-01-13 Thread Tim Chase
On 01/13/13 06:45, subhabangal...@gmail.com wrote: Dear Group, I have a list like, list1=[1,2,3,4,5,6,7,8,9,10,11,12] Now, if I want to take a slice of it, I can. It may be done in, list2=list1[:3] print list2 [snip] Now, I want to combine iterator with a slicing condition like for i=li

Re: For Loop in List

2013-01-13 Thread Dave Angel
On 01/13/2013 07:45 AM, subhabangal...@gmail.com wrote: > Dear Group, > > I have a list like, > list1=[1,2,3,4,5,6,7,8,9,10,11,12] What version of Python? > Now, if I want to take a slice of it, I can. > It may be done in, list2=list1[:3] print list2 > [1, 2, 3] > > If I want to it

For Loop in List

2013-01-13 Thread subhabangalore
Dear Group, I have a list like, >>> list1=[1,2,3,4,5,6,7,8,9,10,11,12] Now, if I want to take a slice of it, I can. It may be done in, >>> list2=list1[:3] >>> print list2 [1, 2, 3] If I want to iterate the list, I may do as, >>> for i in list1: print "Iterated Value Is:",i It