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


Groups > comp.lang.python > #36736

Re: For Loop in List

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!news2.arglkargh.de!nuzba.szn.dk!pnx.dk!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'alternatives': 0.09; 'cc:addr:python-list': 0.10; '-tkc': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'message- id:@tim.thechases.com': 0.16; 'rather,': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'wrote:': 0.17; 'tim': 0.18; 'occurs': 0.22; 'simpler': 0.22; 'cc:no real name:2**0': 0.24; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'cc:addr:gmail.com': 0.27; '>>>>': 0.29; 'chase': 0.29; 'optional': 0.29; 'print': 0.32; 'shorter': 0.33; 'subject:List': 0.33; 'version:': 0.33; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'takes': 0.39; 'little': 0.39; 'subject:For': 0.75; 'boris': 0.84; 'received:50.22': 0.84
Date Sun, 13 Jan 2013 08:07:10 -0600
From Tim Chase <python.list@tim.thechases.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2
MIME-Version 1.0
To Boris FELD <lothiraldan@gmail.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>
In-Reply-To <CAPYZrkBHHUMw87RnuB1BFHAua-fio5u1dOwcvYNBVNj1bkW4_A@mail.gmail.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
Cc Python mailing list <python-list@python.org>, subhabangalore@gmail.com
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.468.1358085942.2939.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1358085942 news.xs4all.nl 6976 [2001:888:2000:d::a6]:44586
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:36736

Show key headers only | 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