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


Groups > comp.lang.python > #32595

Re: pythonic way

References <CAFqGZREfq7fO4Okf1Oj9HBeUkWLYK_9=ho8N47_kyTKudGZSFA@mail.gmail.com> <CANaSqUfRdHoeUzcmAsmaK2WBgbXH63ZDu0pg2ebEX8APKkNwaw@mail.gmail.com> <BLU0-SMTP321F0666E2573FA6807D728F3670@phx.gbl>
Date 2012-11-02 18:56 +1100
Subject Re: pythonic way
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3178.1351842997.27098.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, Nov 2, 2012 at 6:14 PM, jack <naruto0.1@live.cn> wrote:
> Sometimes, I need to alter the element as traverse a list like this (it's a
> sample):
>     c = range(10)
>     i = 0
>     for ele in c:
>         # do something
>         # branch:
>             c[i] = # value
>         i += 1
>
> How to be pythonic?

Check out the enumerate() function.

ChrisA

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


Thread

Re: pythonic way Chris Angelico <rosuav@gmail.com> - 2012-11-02 18:56 +1100

csiph-web