Skip to content

Instantly share code, notes, and snippets.

@sweenist
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sweenist/056a0764fd74ee6f321b to your computer and use it in GitHub Desktop.
Save sweenist/056a0764fd74ee6f321b to your computer and use it in GitHub Desktop.
Python: Increment accidentally 0 indexed lists when the contexts should start at 1
######################################################
### Ever accidentally make a list of immutable tuples
### only to find you used 0 as the base index instead
### of 1? So did I, ergo, unzero_list_of_tuples
### Ever have the reverse happen? use zero_list_of_tuples
######################################################
def unzero_list_of_tuples(t_list):
ret_list = []
for item in t_list:
for i in range(len(item)):
locals()["v" + str(i)] = item[i] + 1
ret_list.append((v0,v1,v2,v3))
return ret_list
def zero_list_of_tuples(t_list):
ret_list = []
for item in t_list:
for i in range(len(item)):
locals()["v" + str(i)] = item[i] - 1
ret_list.append((v0,v1,v2,v3))
return ret_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment