Je dispose d'une liste qui ressemble à ceci :
[
[[0.391, 'J'], [0.366, 'J'], [0.299, '7'], [0.234, '8'], [0.269, '8'], [0.239, 'R'], [0.3, 'K'], 2. 098],
[[0.384, 'J'], [0.387, 'J'], [0.282, '7'], [0.239, '8'], [0.25, '8'], [0.256, 'R'], [0.357, 'K'], 2.155], [[0. 391, 'J'], [0.379, 'J'], [0.458, '7'], [0.235, '8'], [0.289, '8'], [0.275, 'R'], [0.378, 'K'], 2.40500000000002],
[[0. 401, 'J'], [0.462, '7'], [0.422, 'J'], [0.287, '8'], [0.271, '8'], [0.286, 'R'], [0.377, 'K'], 2.50600000000002],
[[0. 382, 'J'], [0.35, 'J'], [0.517, '7'], [0.36, '8'], [0.259, '8'], [0.331, 'R'], [0.36, 'K'], 2.55899999999997],
[[0. 389, 'J'], [0.348, 'J'], [0.499, '7'], [0.369, '8'], [0.365, '8'], [0.289, 'R'], [0.342, 'K'], 2.601], [[0. 352, 'J'], [0.36, 'J'], [0.627, '7'], [0.412, '8'], [0.258, '8'], [0.317, 'R'], [0.383, 'K'], 2.709]
]
C'est essentiellement une liste de listes.
J'ai besoin des lettres et des dernières valeurs Comme ceci : [['J'], ['J'], ['7'], ['8'], ['8'], ['R'], ['K'], 2.098]
, etc.
le code de la liste :
def Trier(liste):
# pour index dans liste:
l = len(liste)
for i in range(0, l):
# pour j dans la plage(0, l):
for j in range(0, l-i-1):
if (liste[j][-1] > liste[j+ 1][-1])
temp = liste[j]
liste[j] = liste[j + 1]
liste[j + 1] = temp
return liste
# print(Trier(liste))
liste_triee = Trier(liste)
print("TRIÉ", liste_triee)