Sorting list/Dic with lambda
1. Sort a List
sorted
1 | sorted(iterable[,key][,reverse]) |
细节
list.sort()
—> sort the list
sorted(list)
—> return a sorted list
1 | # Original list |
2. Sort a dict?
Actually you cannot sort a dictionary, itself has no order.
But you can return a new sorted list
Example:
1 | dic = {'c':1, 'b':2,'a':3} |
2. Use lambda
Sort a list
Example:
1 | L = [ |
Sort a dict (return a list)
Example
1 | dic = { |