The next example demonstrates sorting a list of strings by the length of each string.
This is accomplished by passing the built-in len() function as the keyword parameter value to the list's sort method:
>>> x=['abc', 'erty2222222222', 'zyyzkdl']
>>> x.sort(key=len, reverse=True)
>>> x
['erty2222222222', 'zyyzkdl', 'abc']