Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'elegant': 0.07; 'indices': 0.07; 'python': 0.09; 'sep': 0.09; 'vast': 0.09; 'cc:addr:python- list': 0.10; 'index': 0.13; '-tkc': 0.16; 'better?': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'iterable': 0.16; 'looping': 0.16; 'message-id:@tim.thechases.com': 0.16; 'readability.': 0.16; 'received:70.251': 0.16; 'received:dsl.rcsntx.swbell.net': 0.16; 'received:rcsntx.swbell.net': 0.16; 'received:swbell.net': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'wrote:': 0.17; '>>>': 0.18; 'versions': 0.20; 'define': 0.20; 'earlier': 0.21; '2.x': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; '-0700,': 0.29; "d'aprano": 0.29; 'request,': 0.29; 'steven': 0.29; "i'm": 0.29; 'basic': 0.30; 'code': 0.31; 'getting': 0.33; 'something': 0.35; 'really': 0.36; 'but': 0.36; "wasn't": 0.36; 'anything': 0.36; 'should': 0.36; 'too': 0.36; 'well.': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'where': 0.40; 'time,': 0.62; 'more': 0.63; 'results': 0.65; 'subject:For': 0.75; 'miffed': 0.84; 'occasion': 0.84; 'received:50.22': 0.84; 'seldom': 0.84; 'obvious,': 0.91; 'imagine': 0.96 Date: Sun, 23 Sep 2012 18:29:29 -0500 From: Tim Chase User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111120 Icedove/3.1.16 MIME-Version: 1.0 To: Steven D'Aprano Subject: Re: For Counter Variable References: <10965867-a44f-4146-aea2-fd1a1e8f8e3b@googlegroups.com> <505f9311$0$1612$c3e8da3$76491128@news.astraweb.com> In-Reply-To: <505f9311$0$1612$c3e8da3$76491128@news.astraweb.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 X-Source: X-Source-Args: X-Source-Dir: Cc: python-list@python.org 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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1348442904 news.xs4all.nl 6917 [2001:888:2000:d::a6]:47395 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:29874 On 09/23/12 17:54, Steven D'Aprano wrote: > On Sun, 23 Sep 2012 10:45:53 -0700, jimbo1qaz wrote: >> On Sunday, September 23, 2012 9:36:19 AM UTC-7, jimbo1qaz wrote: >>> Am I missing something obvious, or do I have to manually put in a >>> counter in the for loops? That's a very basic request, but I couldn't >>> find anything in the documentation. >> >> Ya, they should really give a better way, but for now, enumerate works >> pretty well. > > Define "a better way". What did you have in mind that would work better? I can only imagine jimbo1qaz intended "a more C-like way". blech. I **far** prefer The Python Way™. The vast majority of the time, I'm looping over some iterable where indices would only get in the way of readability. Tuple-unpacking the results of enumerate() is an elegant way of getting both the items+indices on the seldom occasion I need the index too (though I'm minorly miffed that enumerate()'s starting-offset wasn't back-ported into earlier 2.x versions and have had to code around it for 1-based indexing; either extra "+1"s or whip up my own simple enumerate() generator). -tkc