Group By Property

Group array items by a property value.

Code

General
from collections import defaultdict
groups = defaultdict(list)
for item in arr:
    groups[item[key]].append(item)
return dict(groups)

Parameters

Array of objects

Property to group by

Server

More Python Snippets