Skip to content

Instantly share code, notes, and snippets.

@jbspeakr
Created April 28, 2015 13:05
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 jbspeakr/c7c4fcb9ee143cf7e9eb to your computer and use it in GitHub Desktop.
Save jbspeakr/c7c4fcb9ee143cf7e9eb to your computer and use it in GitHub Desktop.
Convert Tuple List to Dictionary
"""
usage:
mytool [options]
options:
--foo-bar=PARAM1,PARAM2,... params to do stuff with
[default: key1.value1,key1.value2,key2.value2]
"""
from docopt import docopt
from collections import defaultdict
def run():
params = [tuple(param.strip().split('.')) for param in arguments["--foo-bar"].split(",")]
params = convert_tuple_list_to_dictionary(ignored_resources)
def convert_tuple_list_to_dictionary(list_of_tuple):
dictionary = defaultdict(list)
for k, v in list_of_tuple:
dictionary[k].append(v)
return dictionary
if __name__ == "__main__":
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment