Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '21,': 0.09; 'pm,': 0.10; '>>>': 0.12; 'wrote:': 0.14; 'billy': 0.16; 'clunky.': 0.16; 'properly.': 0.16; 'forgotten': 0.16; 'received:74.125.82.174': 0.16; 'received:mail-wy0-f174.google.com': 0.16; 'cc:addr:python- list': 0.17; 'tue,': 0.17; 'header:In-Reply-To:1': 0.21; 'seems': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'indices': 0.23; 'message-id:@mail.gmail.com': 0.28; 'subject:?': 0.29; 'cc:addr:python.org': 0.30; 'iterating': 0.30; 'it.': 0.31; 'print': 0.31; 'using': 0.35; 'received:google.com': 0.37; 'two': 0.37; 'think': 0.38; 'received:74.125.82': 0.38; 'received:74.125': 0.38; 'could': 0.38; 'subject:: ': 0.38; 'subject:over': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type:content-transfer-encoding; bh=f55RCgautoHlfySp1MwjPDRs05t0qajsZ85rEDDqjuk=; b=TyF8KJRY/5F2+x4QfuISy9ISqwBi/f558ShEBckdKd0VgUVw3BxQX+t0+i+yuC/rd1 uNY+aK6zpYlkKvIVVi9FrbXljzNyCcNkIexhqhULlsrysasmvfI4WhOEqTt3FussgLdY rEyVTEfG4E9Ang0c5QmDZvdFGz+P738qzNC5k= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; b=Lg+zlKylh1tKPIrHADd/VG0/ygWxi1VN4yFRwTC1tWDMl8Y+2zdbqxD0+TfllTttAI LXnZ8YKmDsI2750FttspYMmUrMnH7wdGEjw8plG1/uLtHTZ3VjT4JPY3u7mUYrJj8IbO niMBlqvzG/WwXR9xUn5LaHYKbW52vY/yjwnuo= MIME-Version: 1.0 In-Reply-To: References: From: Noah Hall Date: Tue, 21 Jun 2011 19:19:30 +0100 Subject: Re: Better way to iterate over indices? To: Billy Mays Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 28 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1308680392 news.xs4all.nl 49042 [::ffff:82.94.164.166]:42708 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:8107 On Tue, Jun 21, 2011 at 7:05 PM, Billy Mays wrote: > I have always found that iterating over the indices of a list/tuple is no= t > very clean: > > for i in range(len(myList)): > =A0 =A0doStuff(i, myList[i]) > I know I could use enumerate: > > for i, v in enumerate(myList): > =A0 =A0doStuff(i, myList[i]) > > ...but that stiff seems clunky. You're not using it properly. Think about it. You're giving two names - i and v. You've forgotten about v - >>> for i, v in enumerate('fish'): ... print i, v ... 0 f 1 i 2 s 3 h HTH.