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: 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 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 Subject: Re: For Loop in List References: <50F2B6B0.3080309@tim.thechases.com> In-Reply-To: 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 , 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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 an optional stride. Or rather, I use it so infrequently that I reach for other alternatives before it occurs to me :) -tkc