from itertools import groupby
key = lambda x: x[1][0]
lens = [len(list(g)) for k, g in groupby(sorted(l1, key=key), key=key)]
dct = dict(zip(l2, lens))
How to create a dictionary with certain specific behaviour of values