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


Groups > comp.lang.python > #97070

Re: Idiosyncratic python

Path csiph.com!news.swapon.de!easy.in-chemnitz.de!feeder.erje.net!1.eu.feeder.erje.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!usenetcore.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'url:pypi': 0.03; 'heavily': 0.04; 'defaults': 0.05; 'from:addr:yahoo.co.uk': 0.05; 'pypi': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.10; 'subject:python': 0.14; 'argument': 0.15; 'weird': 0.15; 'item)': 0.16; 'itertools': 0.16; 'people:': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'recipes.': 0.16; 'twin': 0.16; 'wrote:': 0.16; 'language': 0.19; 'latter': 0.22; 'lawrence': 0.22; 'header:In-Reply-To:1': 0.24; 'header:User- Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; '[2]': 0.27; 'print': 0.30; 'creating': 0.30; '[1]': 0.32; 'language.': 0.32; 'url:python': 0.33; 'lets': 0.33; 'item': 0.35; 'but': 0.36; 'there': 0.36; 'url:org': 0.36; 'keyword': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'received:org': 0.37; 'anything': 0.38; 'to:addr:python.org': 0.40; 'mark': 0.40; 'url:3': 0.60; 'email addr:gmail.com': 0.62; 'charset:windows-1252': 0.62; 'more': 0.63; 'hear': 0.64; 'our': 0.64; 'pythonistas,': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Idiosyncratic python
Date Thu, 24 Sep 2015 14:09:28 +0100
References <560391ea$0$2885$c3e8da3$76491128@news.astraweb.com> <mu0eq4$2d2$1@ger.gmane.org> <CAJ4+4aoDY30HmhNrOjG2g+ODoS1vSOMtuANXp0unbuwWcuQd3g@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host 195.147.66.69
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0
In-Reply-To <CAJ4+4aoDY30HmhNrOjG2g+ODoS1vSOMtuANXp0unbuwWcuQd3g@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.123.1443100205.28679.python-list@python.org> (permalink)
Lines 48
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1443100205 news.xs4all.nl 23782 [2001:888:2000:d::a6]:59395
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:97070

Show key headers only | View raw


On 24/09/2015 13:50, paul.hermeneutic@gmail.com wrote:
>  > A lot of our in base weird python comes from heavily C-wired people:
>  >
>  > The classic
>  > for i in range(len(alist)):
>  >   print alist[i]
>  >
>  > with its twin brother
>  >
>  > i=0
>  > while i < len(alist):
>  >   print alist[i]
>  >   i += 1
>  >
>  > And the even more annoying
>  >
>  > result = Result()
>  > getResult(result)
>  >
>  > JM
>
> Please follow up with good ways to write these. I hear that creating one
> really good way is a Python maxim.
>

for item in alist:
     print(item)

If you *think* you need the index:-

for i, item in enumerate(alist):
     print(i, item)
`i` defaults to 0, but there is a `start` keyword argument that lets you 
set it to anything you like.

Better IMHO is to see what the itertools module[1] offers, either 
directly or through recipes.  The latter are available on pypi as 
more-itertools[2].

[1] https://docs.python.org/3/library/itertools.html
[2] https://pypi.python.org/pypi/more-itertools/

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Idiosyncratic python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-09-24 16:02 +1000
  Re: Idiosyncratic python Paul Rubin <no.email@nospam.invalid> - 2015-09-23 23:16 -0700
    Re: Idiosyncratic python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-09-24 16:35 +1000
      Re: Idiosyncratic python Ben Finney <ben+python@benfinney.id.au> - 2015-09-24 16:54 +1000
        Re: Idiosyncratic python Steven D'Aprano <steve@pearwood.info> - 2015-09-25 11:08 +1000
      Re: Idiosyncratic python Terry Reedy <tjreedy@udel.edu> - 2015-09-24 02:54 -0400
  Re: Idiosyncratic python wxjmfauth@gmail.com - 2015-09-24 00:06 -0700
    Re: Idiosyncratic python Laurent Pointal <laurent.pointal@free.fr> - 2015-09-24 19:50 +0200
      Re: Idiosyncratic python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-24 21:05 +0100
  Re: Idiosyncratic python jmp <jeanmichel@sequans.com> - 2015-09-24 11:12 +0200
  Re: Idiosyncratic python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-24 14:09 +0100
  Re: Idiosyncratic python jmp <jeanmichel@sequans.com> - 2015-09-24 16:07 +0200
  Re: Idiosyncratic python Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-24 08:26 -0600
  Re: Idiosyncratic python Chris Angelico <rosuav@gmail.com> - 2015-09-25 02:57 +1000
  Re: Idiosyncratic python jmp <jeanmichel@sequans.com> - 2015-09-24 20:04 +0200
  Re: Idiosyncratic python Ian Kelly <ian.g.kelly@gmail.com> - 2015-09-24 12:19 -0600
  Re: Idiosyncratic python Ned Batchelder <ned@nedbatchelder.com> - 2015-09-24 13:46 -0700
    Re: Idiosyncratic python Laura Creighton <lac@openend.se> - 2015-09-24 23:08 +0200
    Re: Idiosyncratic python Chris Angelico <rosuav@gmail.com> - 2015-09-25 07:49 +1000
    Re: Idiosyncratic python Steven D'Aprano <steve@pearwood.info> - 2015-09-25 10:55 +1000
  Re: Idiosyncratic python sohcahtoa82@gmail.com - 2015-09-24 15:32 -0700
  Re: Idiosyncratic python Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-09-25 00:40 +0100
  Re: Idiosyncratic python Akira Li <4kir4.1i@gmail.com> - 2015-09-25 03:04 +0300
  Re: Idiosyncratic python Steven D'Aprano <steve@pearwood.info> - 2015-09-25 10:08 +1000

csiph-web