Last active
August 29, 2015 14:12
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###################################################### | |
### 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