“Como classificar a lista aninhada em Python” Respostas de código

classificar a lista aninhada de Python de acordo com um valor

name_age = [["A", 7], ["B", 5], ["C", 35]]
name_age.sort(key=lambda age: age[1])
#name_age.sort(key=lambda age: age[1], reverse = True)
print(name_age)

#sorts according to the 1th value of the inner loop
motinxy

Classificação por segundo elemento

sorted(LISTNAME, key=lambda x: x[1])
Protelr

Como classificar a lista aninhada em Python

# Python code to sort the lists using the second element of sublists
# Inplace way to sort, use of third variable
def Sort(sub_li):
    l = len(sub_li)
    for i in range(0, l):
        for j in range(0, l-i-1):
            if (sub_li[j][1] > sub_li[j + 1][1]):
                tempo = sub_li[j]
                sub_li[j]= sub_li[j + 1]
                sub_li[j + 1]= tempo
    return sub_li
  
# Driver Code
sub_li =[['rishav', 10], ['akash', 5], ['ram', 20], ['gaurav', 15]]
print(Sort(sub_li))
android developer

Respostas semelhantes a “Como classificar a lista aninhada em Python”

Perguntas semelhantes a “Como classificar a lista aninhada em Python”

Mais respostas relacionadas para “Como classificar a lista aninhada em Python” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código