Commit b322d327 authored by Dominik Rimpf's avatar Dominik Rimpf
Browse files

CHG: helper function implemented as generator, docstrings

parent 6607faf3
Pipeline #112464 passed with stage
in 22 seconds
......@@ -24,13 +24,18 @@ class ArgumentParser(argparse.ArgumentParser):
def dict_by_value_of_list(array, value):
"""Mapping function to convert list of dicts to an dict with value as key for each dict. (1 to 1 Mapping)
Returns an generator object."""
return ((item[value], item) for item in array)
def dict_of_lists_by_value_of_list(array, value):
"""Mapping function to convert list of dicts to an dict with values as key for each lists. (1 to n Mapping)
Returns an generator object."""
res = {}
for item in array:
if not item[value] in res:
res[item[value]] = []
res[item[value]].append(item)
return res
for key, value in res.items():
yield key, value
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment