>>> s = [('yellow', 1), ('blue', 2), ('yellow', 3), ('blue', 4), ('red', 1)]
>>> d = defaultdict(list)
>>> for k, v in s:
... d[k].append(v)
...
>>> d.items()
[('blue', [2, 4]), ('red', [1]), ('yellow', [1, 3])]
from itertools import groupby
from operator import itemgetter
l = [(1, 1), (1, 2), (2, 1), (2, 3), (2, 5), (2, 7)]
for p, q in groupby(l, itemgetter(0)):
print(p, list(map(itemgetter(1), q)))