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