I have this data:
self.data = [(1, 1, 5.0), (1, 2, 3.0), (1, 3, 4.0), (2, 1, 4.0), (2, 2, 2.0)] >
self.data = [(1, 1, 5.0), (1, 2, 3.0), (1, 3, 4.0), (2, 1, 4.0), (2, 2, 2.0)]
Variant without sorting (via dictionary). Should be better performance-wise.
def full_group_by(l, key=lambda x: x): d = defaultdict(list) for item in l: d[key(item)].append(item) return d.items()