huge rewrite, split to base and yandex-specific parts

There is library [function](https://docs.python.org/3.4/library/itertools.html#itertools.groupby) with such name (functionality?).
If you can't use standard function, needs to rename your function.