Skip to main content

Timeline for answer to How can I access the index value in a 'for' loop? by A.J.

Current License: CC BY-SA 4.0

Post Revisions

16 events
when toggle format what by license comment
Jun 23, 2022 at 23:40 history edited SuperStormer CC BY-SA 4.0
typo
Apr 20, 2022 at 11:46 review Low quality answers
Apr 20, 2022 at 14:35
Aug 22, 2021 at 6:24 review Suggested edits
Aug 23, 2021 at 20:34
Feb 5, 2021 at 12:29 history edited mhhabib CC BY-SA 4.0
print() function modified according to python 3.x+
Oct 6, 2020 at 18:24 history edited ShadowRanger CC BY-SA 4.0
Note no longer relevant since tuple being unpacked.
Oct 6, 2020 at 18:23 comment added ShadowRanger @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.
Apr 20, 2019 at 12:52 history undeleted Jean-François Fabre
Apr 20, 2019 at 12:51 history deleted Jean-François Fabre via Vote
Nov 30, 2018 at 18:24 comment added pushkin @AnttiHaapala The reason, I presume, is that the question's expected output starts at index 1 instead 0
Jul 25, 2018 at 10:55 history edited A.J. CC BY-SA 4.0
added 11 characters in body
Jan 2, 2018 at 11:31 comment added hygull Better is to enclose index inside parenthesis pairs as (index), it will work on both the Python versions 2 and 3.
Sep 17, 2016 at 10:15 history edited Peter Mortensen CC BY-SA 3.0
Copy edited. (its = possessive, it's = "it is" or "it has". See for example <http://www.wikihow.com/Use-Its-and-It%27s>.)
Mar 18, 2016 at 9:18 comment added Antti Haapala 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).
Nov 30, 2015 at 11:10 history edited A.J. CC BY-SA 3.0
deleted 1 character in body
Feb 20, 2015 at 10:16 history edited A.J. CC BY-SA 3.0
added 116 characters in body
May 27, 2014 at 10:04 history answered A.J. CC BY-SA 3.0