For Loop in List

Boris FELD lothiraldan at gmail.com
Sun Jan 13 14:48:50 CET 2013


2013/1/13 Tim Chase <python.list at tim.thechases.com>:
> On 01/13/13 06:45, subhabangalore at 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 range(0,len(x),SIZE):
...      print x[i: i+SIZE]
...
[1, 2, 3]
[4, 5, 6]
[7, 8, 9]
[10, 11, 12]

Hope it helps

> Hope this helps,
>
> -tkc



More information about the Python-list mailing list