Conditions | 5 |
Total Lines | 12 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | from benedict.utils import type_util |
||
4 | def groupby(items, key): |
||
5 | if not type_util.is_list(items): |
||
6 | raise ValueError("items should be a list of dicts.") |
||
7 | items_grouped = {} |
||
8 | for item in items: |
||
9 | if not type_util.is_dict(item): |
||
10 | raise ValueError("item should be a dict.") |
||
11 | group = item.get(key) |
||
12 | if group not in items_grouped: |
||
13 | items_grouped[group] = [] |
||
14 | items_grouped[group].append(item.copy()) |
||
15 | return items_grouped |
||
16 |