bug with itertools.groupby?
Diez B. Roggisch
deets at nospam.web.de
Tue Oct 6 19:12:42 EDT 2009
Kitlbast schrieb:
> Hi there,
>
> the code below on Python 2.5.2:
>
> from itertools import groupby
>
> info_list = [
> {'profile': 'http://somesite.com/profile1', 'account': 61L},
> {'profile': 'http://somesite.com/profile2', 'account': 64L},
> {'profile': 'http://somesite.com/profile3', 'account': 61L},
> ]
>
> grouped_by_account = groupby(info_list, lambda x: x['account'])
> for acc, iter_info_items in grouped_by_account:
> print 'grouped acc: ', acc
>
> gives output:
>
> grouped acc: 61
> grouped acc: 64
> grouped acc: 61
>
> am I doing something wrong?
http://docs.python.org/library/itertools.html#itertools.groupby
"""
Generally, the iterable needs to already be sorted on the same key function.
"""
Diez
More information about the Python-list
mailing list