from itertools import *
import operator
import pprint
import functools
@functools.total_ordering
class Point:
def __init__(self, x, y):
self.x = x
self.y = y
def __repr__(self):
return str((self.x, self.y))
def __eq__(self, other):
return self.x == other.x & self.y == other.y
def __lt__(self, other):
return self.x < other.x
data = list(map(Point, cycle(islice(count(), 3)), islice(count(), 7)))
pprint.pprint(data)
for k, g in groupby(data, operator.attrgetter('x')):
print(k, list(g))
data.sort()
pprint.pprint(data)
for k, g in groupby(data, operator.attrgetter('x')):
print(k, list(g))