easy +10 pts

Order by Name

Sort a list of names alphabetically, case-insensitively.

Write a function `order_by_name(names)` that takes a list of strings (names) and returns a new list with the names sorted in alphabetical order, ignoring case (so 'alice', 'Bob', 'charlie' sorts as ['alice', 'Bob', 'charlie']). The original list should remain unchanged. The sort should be stable: if two names are the same when case is ignored, their original relative order must be preserved. The function must not modify the input list.

Constraints

Input list length: 0 to 1000. Each name is a non-empty string of printable ASCII characters. Time complexity O(n log n), space complexity O(n).

Example

>>> order_by_name(['bob', 'Alice', 'carol'])
['Alice', 'bob', 'carol']
>>> order_by_name(['Zoe', 'amy', 'Bob'])
['amy', 'Bob', 'Zoe']
>>> order_by_name([])
[]
10 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Use the `sorted` function with a `key` parameter.
To sort case-insensitively, use `key=str.lower`.
The `sorted` function returns a new list and does not modify the original.
Python's sort is stable, so equal keys preserve original order automatically.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.