Skip to main content
Active reading [<https://en.wiktionary.org/wiki/Pythonic#Adjective>].
Source Link
Peter Mortensen
  • 31.1k
  • 22
  • 111
  • 134

Use the built-in function enumerate():

for idx, x in enumerate(xs):
    print(idx, x)

It is non-pythonicPythonic to manually index via for i in range(len(xs)): x = xs[i] or manually manage an additional state variable.

Check out PEP 279 for more.

Use the built-in function enumerate():

for idx, x in enumerate(xs):
    print(idx, x)

It is non-pythonic to manually index via for i in range(len(xs)): x = xs[i] or manually manage an additional state variable.

Check out PEP 279 for more.

Use the built-in function enumerate():

for idx, x in enumerate(xs):
    print(idx, x)

It is non-Pythonic to manually index via for i in range(len(xs)): x = xs[i] or manually manage an additional state variable.

Check out PEP 279 for more.

Move code sample above. Give example of what idiom is specifically considered non-pythonic.
Source Link
Mateen Ulhaq
  • 28.1k
  • 22
  • 122
  • 157

Using an additional state variable, such as an index variable (which you would normally use in languages such as C or PHP), is considered non-pythonic.

The better option is to useUse the built-in function enumerate(), available in both Python 2 and 3:

for idx, valx in enumerate(intsxs):
    print(idx, valx)

It is non-pythonic to manually index via for i in range(len(xs)): x = xs[i] or manually manage an additional state variable.

Check out PEP 279 for more.

Using an additional state variable, such as an index variable (which you would normally use in languages such as C or PHP), is considered non-pythonic.

The better option is to use the built-in function enumerate(), available in both Python 2 and 3:

for idx, val in enumerate(ints):
    print(idx, val)

Check out PEP 279 for more.

Use the built-in function enumerate():

for idx, x in enumerate(xs):
    print(idx, x)

It is non-pythonic to manually index via for i in range(len(xs)): x = xs[i] or manually manage an additional state variable.

Check out PEP 279 for more.

Copy edited.
Source Link
Peter Mortensen
  • 31.1k
  • 22
  • 111
  • 134

Using an additional state variable, such as an index variable (which you would normally use in languages such as C or PHP), is considered non-pythonic.

The better option is to use the builtinbuilt-in function enumerate(), available in both Python 2 and 3:

for idx, val in enumerate(ints):
    print(idx, val)

Check out PEP 279 for more.

Using additional state variable, such as index variable (which you would normally use in languages such as C or PHP), is considered non-pythonic.

The better option is to use the builtin function enumerate(), available in both Python 2 and 3:

for idx, val in enumerate(ints):
    print(idx, val)

Check out PEP 279 for more.

Using an additional state variable, such as an index variable (which you would normally use in languages such as C or PHP), is considered non-pythonic.

The better option is to use the built-in function enumerate(), available in both Python 2 and 3:

for idx, val in enumerate(ints):
    print(idx, val)

Check out PEP 279 for more.

Switch the top answer to Python 3; Python 2 users can work out differences.
Source Link
Antti Haapala
  • 134.9k
  • 23
  • 299
  • 350
Loading
deleted 10 characters in body
Source Link
Aaron Hall
  • 401.7k
  • 94
  • 418
  • 342
Loading
Bounty Awarded with 500 reputation awarded by Tadeck
added 118 characters in body
Source Link
Mike Hordecki
  • 98.3k
  • 3
  • 30
  • 28
Loading
Source Link
Mike Hordecki
  • 98.3k
  • 3
  • 30
  • 28
Loading