Skip to content

Instantly share code, notes, and snippets.

@miratcan
Created May 9, 2013 11:23
Show Gist options
  • Save miratcan/5546928 to your computer and use it in GitHub Desktop.
Save miratcan/5546928 to your computer and use it in GitHub Desktop.
Convert tuple groups (that has no constant length) into dict object.
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