How to sort a list alphabetically by the second word in a string

Viewed 17023

If I have a list and I want to keep adding lines to it and sorting them alphabetically by their last name, how could this be done? Sorted only seems to rearrange them by the first letter of the string.

    line = "James Edward"   #Example line
    linesList.append("".join(line))   #Add it to a list
    linesList = sorted(linesList)   #Sort alphabetically
4 Answers
Related