“Python sort () i sorted ()” Kod odpowiedzi

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

Python sort () i sorted ()

a=[2,2,4,1]
b=a
a.sort()
// a now points to object [1,2,2,4]
c=sorted(b)
//c and b also points to [1,2,2,4] 
// sort works on array only but sorted also on strings but return array of char
s="sjndk"
print(sorted(s))
// prints ['d', 'j', 'k', 'n', 's']
// sorted also works on list of strings(sorts alphabetically)
ap_Cooperative_dev

Odpowiedzi podobne do “Python sort () i sorted ()”

Pytania podobne do “Python sort () i sorted ()”

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

Przeglądaj inne języki kodu