Sorted functions and Sort methods
- Sorted (iterable) #原容器不变, returns the list, the container can be set,dict (returns a sorted list of keys)
- List.sort () #修改原列表
Sorted ():
- Sorted (iterable, Cmp=none, Key=none, Reverse=false)--New sorted list
- CMP: comparison function, customizable:
# sorted by bit size, CMP functions are defined as x > y positive, x < y negative, x = = y is 0f = lambda x,y:1 if x%10 > y%10 Else ( -1 if x%10 < y%10 el SE 0) # Unified into lowercase sort cmp=lambda x,y:cmp (X.lower (), Y.lower ())
- Key: Sort element function, specifying what list elements to sort by
# You can sort the string in bits of its number, F is the sort function sorted (["321", "123", "231", "222"], cmp=f, Key=int)
- Reverse: whether to reverse
L.sort (Cmp=none, Key=none, Reverse=false)-stable sort *in place*;
Similar to sorted, it will only modify the original L
Python Sort Function Summary