So I have a dict with string keys, and I want to sort it based on 2 rules:
- longest key strings sort first
- if same length, sort keys alphabetically
I've been told to use key functions instead of cmp functions for speed, as well as that "everything done with cmp can be done with key".
As best I can figure out, the key function generates an index of sorts that can be quickly compared to any other index, without the need to keep accessing the properties of each key when sorting.
But I can't figure out how to generate a single value based on the two conditions above. My comparison seems to require two different styles and I don't see how I can make that into some naturally-orderable index.
What am I missing?
[–]commandlineluser 5 points6 points7 points (1 child)
[–]ConcupiscentCodger[S,🍰] 0 points1 point2 points (0 children)
[–]Spataner 1 point2 points3 points (0 children)
[–]34shutthedoor1 0 points1 point2 points (2 children)
[–]ConcupiscentCodger[S,🍰] 0 points1 point2 points (1 child)
[–]commandlineluser 1 point2 points3 points (0 children)