Itertools Hackerrank Solution Python