Basically I've found this and similar code a bunch of times now:
items_by_parent = defaultdict(list)
for item in items:
items_by_parent[item.parent].append(item)
I come from a C# background and was a heavy linq user where you'd go list.GroupBy(...).ToDictionary(...)
, so this snippet grinds my gears to some extent. Which leads me to ask: Is there some functional way to achieve the same result in python?
Thanks :)