Created
May 9, 2013 11:23
-
-
Save miratcan/5546928 to your computer and use it in GitHub Desktop.
Convert tuple groups (that has no constant length) into dict object.
This file contains hidden or 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
def list_to_dict(l): | |
""" | |
This method converts tuple groups (that has no constant length) into | |
dict object. | |
>>> l = ((1, 'foo', 'bar'), (2, 'ta', 'ran', 'ti', 'no')) | |
>>> list_to_dict(l) | |
..: {'1': (foo, bar), 2: ('ta', 'ran', 'ti', 'no')} | |
""" | |
resp = {} | |
for item in l: | |
resp.update({item[0]: item[1:]}) | |
return resp | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment