Created
April 28, 2015 13:05
-
-
Save jbspeakr/c7c4fcb9ee143cf7e9eb to your computer and use it in GitHub Desktop.
Convert Tuple List to Dictionary
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
""" | |
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