benedict.core.groupby   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 14
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A groupby() 0 12 5
1
from benedict.utils import type_util
2
3
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