itertools.groupby(iterable[, key])
from itertools import groupby
input:[k for k, g in groupby('AAAABBBCCDAABBB')]
output:['A', 'B', 'C', 'D', 'A', 'B']
input:[list(g) for k, g in groupby('AAAABBBCCD')]
output:[['A', 'A', 'A', 'A'], ['B', 'B', 'B'], ['C', 'C'], ['D']]