Itertools group by functionality
Posted
by Nil
on Stack Overflow
See other posts from Stack Overflow
or by Nil
Published on 2010-04-07T10:29:02Z
Indexed on
2010/04/07
10:33 UTC
Read the original article
Hit count: 485
I want to group by on dict key
>>> x
[{'a': 10, 'b': 90}, {'a': 20}, {'a': 30}, {'a': 10}]
>>> [(name, list(group)) for name, group in groupby(x, lambda p:p['a'])]
[(10, [{'a': 10, 'b': 90}]), (20, [{'a': 20}]), (30, [{'a': 30}]), (10, [{'a': 10}])]
This must group on key 10 :(
© Stack Overflow or respective owner