Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def tri_comptage(liste):
- #on trouve d'abord le max et le min de la liste
- maximum = liste[0]
- minimum = liste[0]
- for j in range(len(liste)):
- if liste[j] > maximum:
- maximum = liste[j]
- elif liste[j] < minimum:
- minimum = liste[j]
- #on cree la liste pour compter le nombre d'occurrences de valeurs
- liste_comptage = []
- for i in range(0, maximum):
- liste_comptage += [i]
- liste_comptage[i] = 0
- #remplissage de la liste d'occurrences de valeurs
- for k in range(len(liste)):
- liste_comptage[liste[k] - minimum] = liste_comptage[liste[k] - minimum] + 1
- #transfert de la liste d'occurrences a la liste de valeurs
- indice = 0
- for l in range(len(liste_comptage)):
- while liste_comptage[l] > 0:
- liste[indice] = l + minimum
- indice += 1
- liste_comptage[l] -= 1
- return liste
- print(tri_comptage([1, 15, 20, 16, 2]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement