Discussion about this post

User's avatar
Paul's avatar

Hi, I really liked your article. Never realised that keys can be supplied in so many places!

Please note that instead of sorting twice to get a list of names sorted on nr of 'a's and names with equal nr of 'a's alphabetically , you could sort just once:

sort_names.sort(key=lambda x: (x.lower().count('a'), x))

Expand full comment
Abhinav Upadhyay's avatar

This was probably the most confusing thing in Python when I started, and the docstring of sorted never helped :)

Expand full comment
5 more comments...

No posts