Python Itertools Group By Function