Sort by Surname

Python for AIMedium+10 XP+10

Sort by Surname

A guest list holds full names like "Ada Lovelace": always a first name, one space, then a surname.

Write by_surname(guests). It returns a new list of the full names sorted A to Z by surname, ignoring capitals ("de" and "De" sort the same).

  • Guests with the same surname (ignoring capitals) keep their original order.
  • Return the names exactly as given; don't change their capitals.

Examples

guests = ["Grace Hopper", "Ada Lovelace", "alan turing", "Charles babbage"]
returns ['Charles babbage', 'Grace Hopper', 'Ada Lovelace', 'alan turing']
guests = []
returns []

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run