“Python Dict Sorderen” Kod odpowiedzi

Sortuj słownik Python

l = {1: 40, 2: 60, 3: 50, 4: 30, 5: 20}
d1 = dict(sorted(l.items(),key=lambda x:x[1],reverse=True))
print(d1) #output : {2: 60, 3: 50, 1: 40, 4: 30, 5: 20}
d2 = dict(sorted(l.items(),key=lambda x:x[1],reverse=False))
print(d2) #output : {5: 20, 4: 30, 1: 40, 3: 50, 2: 60}
Rajanit Navapara

Sortuj słownik w Pythonie

d = {2: 3, 1: 89, 4: 5, 3: 0}
od = sorted(d.items())
print(od)
Clean Cicada

Python Dict Sorderen

# dict has no order - use a list to store
l = {1: 40, 2: 60, 3: 50, 4: 30, 5: 20}
d1 = list(sorted(l.items(),key=lambda x:x[1],reverse=True))
Marc Tolkmitt

Odpowiedzi podobne do “Python Dict Sorderen”

Pytania podobne do “Python Dict Sorderen”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu