Skip to content

Instantly share code, notes, and snippets.

@ehermes
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save ehermes/d119baf2b08adea88ec5 to your computer and use it in GitHub Desktop.

Select an option

Save ehermes/d119baf2b08adea88ec5 to your computer and use it in GitHub Desktop.
foo = [0, 1, 2]
# wrong
for n in foo:
n += 1
print foo
# right
for i in range(len(foo)):
foo[i] += 1
print foo
# also works i guess?
for i, n in enumerate(foo):
foo[i] += 1
print foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment