New submission from Jiba <jibal...@free.fr>: In some situation, itertools.groupby fails to group the objects, and produces several groups with the same key. For example, the following code :
from itertools import * class P(object): def __init__(self, key): self.key = key p1 = P(1) p2 = P(2) p3 = P(1) for key, ps in groupby([p1, p2, p3], lambda p: p.key): print "group", key for p in ps: print " - object", p Produces the following result : group 1 - object <__main__.P object at 0xb73d6acc> group 2 - object <__main__.P object at 0xb73d6aec> group 1 - object <__main__.P object at 0xb73d6b0c> While I would expect to have only a single group 1, e.g. something like : group 1 - object <__main__.P object at 0xb73d6acc> - object <__main__.P object at 0xb73d6b0c> group 2 - object <__main__.P object at 0xb73d6aec> It seems that this bug also affects Python 3 (tested on Python 3.1.2) ---------- components: Library (Lib) messages: 160822 nosy: Jiba priority: normal severity: normal status: open title: itertools.groupby not working as expected type: behavior versions: Python 2.7 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue14828> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com