Python sort by multiple keys
Say we have [code] L = [“a”, “b”, “zz”, “zzz”, “aa”] [/code] We want to sort by length first, then by alphabetical order. i.e. we want to obtain [‘a’, ‘b’, ‘aa’, ‘zz’, ‘zzz’] in the end. How to do that? The usual sorted() will give us this. [code] > sorted(L) [‘a’, ‘aa’, ‘b’, ‘zz’, ‘zzz’] [/code] Very much alphabetical, not what we want. Try sorted() with key=len will give us this. ...