Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #36736

Re: For Loop in List

Date 2013-01-13 08:07 -0600
From Tim Chase <python.list@tim.thechases.com>
Subject Re: For Loop in List
References <f14eb990-b951-4e57-bc70-4a85f837aa51@googlegroups.com> <50F2B6B0.3080309@tim.thechases.com> <CAPYZrkBHHUMw87RnuB1BFHAua-fio5u1dOwcvYNBVNj1bkW4_A@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.468.1358085942.2939.python-list@python.org> (permalink)

Show all headers | View raw


On 01/13/13 07:48, Boris FELD wrote:
> 2013/1/13 Tim Chase <python.list@tim.thechases.com>:
>>>>> 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 an optional stride.  Or 
rather, I use it so infrequently that I reach for other alternatives 
before it occurs to me :)

-tkc


Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

For Loop in List subhabangalore@gmail.com - 2013-01-13 04:45 -0800
  Re: For Loop in List Dave Angel <d@davea.name> - 2013-01-13 08:20 -0500
  Re: For Loop in List Tim Chase <python.list@tim.thechases.com> - 2013-01-13 07:29 -0600
  Re: For Loop in List Boris FELD <lothiraldan@gmail.com> - 2013-01-13 14:48 +0100
  Re: For Loop in List Tim Chase <python.list@tim.thechases.com> - 2013-01-13 08:07 -0600
  Re: For Loop in List Mitya Sirenef <msirenef@lightbird.net> - 2013-01-13 12:41 -0500

csiph-web