“Lista sortowania Python” Kod odpowiedzi

Lista sortowania listy

>>> lis = [[1,4,7],[3,6,9],[2,59,8]]
>>> sorted(lis, key=lambda x: x[0])
[[1, 4, 7], [2, 59, 8], [3, 6, 9]]
Bloody Bug

Jak posortować listę opadającą Python

# defning A as a list
A.sort(reverse = True)
Last_Guardian

Python sort

>>> student_tuples = [
...     ('john', 'A', 15),
...     ('jane', 'B', 12),
...     ('dave', 'B', 10),
... ]
>>> sorted(student_tuples, key=lambda student: student[2])   # sort by age
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
Puzzled Pheasant

Jak sortować w Pythonie

a=[1,6,10,2,50,69,3]
print(sorted(a))
Thiêm KTH

Jak posortować listę w Pythonie

l=[1,3,2,5]
l= sorted(l)
print(l)
#output=[1, 2, 3, 5]
#or reverse the order:
l=[1,3,2,5]
l= sorted(l,reverse=True)
print(l)
#output=[5, 3, 2, 1]
SimTheGreat

Lista sortowania Python

>>> L = ['abc', 'ABD', 'aBe']
>>> sorted(L, key=str.lower, reverse=True) # Sorting built-in
['aBe', 'ABD', 'abc']
>>> L = ['abc', 'ABD', 'aBe']
>>> sorted([x.lower() for x in L], reverse=True)
['abe', 'abd', 'abc']
David Cao

Odpowiedzi podobne do “Lista sortowania Python”

Pytania podobne do “Lista sortowania Python”

Więcej pokrewnych odpowiedzi na “Lista sortowania Python” w Python

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

Przeglądaj inne języki kodu