P10 solution, naive and unpython-like
Better solution to p10 using groupby module