Sorted (Dic.items (),key=Lambdaitem:item[0])
Related Knowledge collation
1, sorted ()
Sorted (iterable, Key=none, Reverse=false)
Iterable: An Iterative object
Key: Specifies a function that is used tofromin IterableIn each element of theextracts a property to act as aThe keyword used for comparison. The default value is None.
Reverse: Default is Fale, true when list elements are sorted in reverse order
Returns a new list
RightiterableSort by the function of key
2, Dic.iteMs( )
Dict.items () returns a list of the dictionary's (key, value) tuple pairs
3. Lambda Item:item[0]
anonymous function, take the No. 0 element of item
Summarize:
Sorted (Dic.items (),key= Lambda item:item[0])
iterable section:theDic.items ()To sort,dic.items () Returns a list of the tuple pairs that the list element is a dictionary. such as [(1, ' A '), (2, ' B ')]
Key part: For a function, this function takes item[0], that is, the list of each element of the No. 0 bit to compare sort. Compare 1, 2 in [(1, ' A '), (2, ' B ')]
Python dictionary sort