Convert array of letters into their counts with Python
Solution 1:
Seems like a good use of itertools.groupby
:
from itertools import groupby
l = ['A','A','A','B','B','C','A','A','D','D','D','B']
[f'{len(list(g))}{k}' for k, g in groupby(l)]
# ['3A', '2B', '1C', '2A', '3D', '1B']