Brandon T. answered • 05/28/19

Python Expert

Algorithmically speaking, you could write your own lexicographical sort. The specifications of this algorithm including implementation and time complexity is over-kill if you have a small dataset.

In Python you could simply write:

sorted(s, key=str.upper) or sorted(s, key=str.lower)

A search on StackOverFlow shows this solution as well:

sorted(sorted(s), key=str.upper)

Since the Python sorted() function would run much faster on a list that was already sorted once.

In general it is typically not worth re-writing Python's built in sorting function because the sorting algorithm it uses is Timsort. Timsort is an algorithm written as Python's internal sort function which is a combination of merge-sort and insertion-sort.

It would be difficult to write a sorting algorithm that performs better than Timsort, but of course it is entirely possible and I encourage you to take a crack at it for fun.