pythonic way

Chris Angelico rosuav at gmail.com
Fri Nov 2 08:56:33 CET 2012


On Fri, Nov 2, 2012 at 6:14 PM, jack <naruto0.1 at 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


More information about the Python-list mailing list