Message160822
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) |
|
Date |
User |
Action |
Args |
2012-05-16 09:51:34 | Jiba | set | recipients:
+ Jiba |
2012-05-16 09:51:34 | Jiba | set | messageid: <1337161894.62.0.255300061013.issue14828@psf.upfronthosting.co.za> |
2012-05-16 09:51:34 | Jiba | link | issue14828 messages |
2012-05-16 09:51:33 | Jiba | create | |
|