from itertools import groupby
a = [1, 2, 3, 2, 2, 2, 3, 3, 4, 4, 4, 3, 1, 1]
a = sorted(a)
#Regrouper les éléments contigus
for key, group in groupby(a):
print list(group)
Résultat d'exécution
[1, 1, 1]
[2, 2, 2, 2]
[3, 3, 3, 3]
[4, 4, 4]
Recommended Posts