Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 17
    The question was about list indexes; since they start from 0 there is little point in starting from other number since the indexes would be wrong (yes, the OP said it wrong in the question as well). Otherwise, calling the variable that is tuple of index, item just index is very misleading, as you noted. Just use for index, item in enumerate(ints). Commented Mar 18, 2016 at 9:18
  • 1
    Better is to enclose index inside parenthesis pairs as (index), it will work on both the Python versions 2 and 3.
    – hygull
    Commented Jan 2, 2018 at 11:31
  • 2
    @AnttiHaapala The reason, I presume, is that the question's expected output starts at index 1 instead 0
    – pushkin
    Commented Nov 30, 2018 at 18:24
  • @hygull: Turning index into (index) won't change a thing on either Py2 or Py3. I feel like maybe you're thinking of the change to print; the only way to make that work on both Py2 and Py3 is to add from __future__ import print_function to the top of your file to get consistent Py3-style print, and change the print to print(index, item). Or you read an earlier edit of the question when index was the original tuple, not unpacked to two names, but the parentheses still don't change anything if you fail to unpack. Commented Oct 6, 2020 at 18:23