If I have a list of tuples that such as names = [('first1,last1'), ('first2,last2'),...]
I know I can sort them alphabetically with the built-in sort
by simply doing
sorted_names = sorted(names, key=lambda tup: (tup[1],tup[0]))
However, I want to know how exactly python is using the key. For instance, if I wanted to make my own sort function with a key parameter how would it be implemented? My guess would be something like
def my_sort(list, key):
interpret the key in some way
sort the list based on the key
return list
I've looked through the documentation and couldn't find what I was looking for.