Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Foote Newsgroups: comp.lang.python Subject: Re: The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?) Date: Tue, 22 Mar 2016 11:27:57 +0000 Lines: 31 Message-ID: References: <56e44258$0$1598$c3e8da3$5496439d@news.astraweb.com> <8737rvxs89.fsf@elektro.pacujo.net> <56e7483d$0$1608$c3e8da3$5496439d@news.astraweb.com> <56f09973$0$1601$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de dsc+9WATNYGlS6cr4qOWGAxg1hcCv3OvH6uJuRy5S0VA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'preference': 0.05; 'builtin': 0.07; 'python:': 0.09; 'subject:which': 0.09; 'way:': 0.09; 'index': 0.13; 'from:addr:ian': 0.16; 'pythonic': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:?)': 0.16; 'wrote:': 0.16; 'pascal': 0.22; 'written': 0.24; 'header:In-Reply- To:1': 0.24; 'header:User-Agent:1': 0.26; 'function': 0.28; 'index,': 0.29; 'received:dreamhost.com': 0.29; 'received:g.dreamhost.com': 0.29; 'work.': 0.30; 'code': 0.30; 'probably': 0.31; "d'aprano": 0.33; 'steven': 0.33; 'item': 0.35; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; "won't": 0.38; 'received:192': 0.39; 'skip:e 20': 0.39; 'to:addr:python.org': 0.40; 'subject:The': 0.61; 'charset:windows-1252': 0.62; 'idiomatic': 0.84 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=feete.org; h=subject:to :references:from:message-id:date:mime-version:in-reply-to :content-type:content-transfer-encoding; s=feete.org; bh=hGZEkPV ZzxtFslfZSBc4QvSZHuY=; b=PeqRufHbfVx7zoloyORuJGf6vgN7gsScOd276SF mpD9VaX3pWW8l+mAxoUFEVH6tG5BH6EG9Y419X594l+HSiFik04Fk3k15Zq7I3r3 rU3wztzQXzlCJjZNmVryTZCgOVOGMbjJ3Gv0/bms6BNSDN/kOi6JyPB2gd4uUXeO 89BE= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105465 On 22/03/16 11:05, BartC wrote: > On 22/03/2016 01:01, Steven D'Aprano wrote: > >> Pythonic code probably uses a lot of iterables: >> >> for value in something: >> ... > >> in preference to Pascal code written in Python: >> >> for index in range(len(something)): >> value = something[index] > > (Suppose you need both the value and its index in the loop? Then the > one-line for above won't work. For example, 'something' is [10,20,30] > and you want to print: > > 0: 10 > 1: 20 > 2: 30 ) > The builtin enumerate function is the idiomatic way: for index, item in enumerate(something): ... Regards, Ian F