from itertools import groupby
a = [1, 2, 3, 2, 2, 2, 3, 3, 4, 4, 4, 3, 1, 1]
a = sorted(a)
#Gruppieren Sie zusammenhängende Elemente
for key, group in groupby(a):
print list(group)
Ausführungsergebnis
[1, 1, 1]
[2, 2, 2, 2]
[3, 3, 3, 3]
[4, 4, 4]
Recommended Posts