In fact, you sort by the last letter, and not by name, considering the last word after the space always using the separation of the last name:
l = ['John Fine', 'Doug Biro', 'Jo Ann Alfred'] sorted(l, key=lambda x: x.rsplit(None,1)[-1])
If you want the name-based min value to use min :
print(min(l,key=lambda x: x.rsplit(None,1)[-1]))
For reverse use max .
lambda x: x.rsplit(None,1)[-1] actually splits the line at the last space and uses this value as a key for sorting.
source share