I don’t think that I found out a bug but it doesn’t look normal to me.
from itertools import groupby
from operator import itemgetter
c=[((u'http://www.example.com', u'second_value'), u'one'),
((u'http://www.example.com', u'second_value'), u'two'),
((u'http://www.hello.com', u'second_value'), u'one'),
((u'http://www.example.com', u'second_value'), u'three'),
((u'http://www.hello.com', u'second_value'), u'two')]
b= groupby(c, key=itemgetter(0))
for unique_keys, group in b:
print unique_keys
Yields:
(u'http://www.example.com', u'second_value')
(u'http://www.hello.com', u'second_value')
(u'http://www.example.com', u'second_value')
(u'http://www.hello.com', u'second_value')
Any explanations ? (I was expecting only two different keys). I am using python 2.7.1 if that makes a difference
The iterable needs to already be sorted (on the same key function):
out: