Loading exercise...

Exercise: Sort a List of Words, Longest First

Avatar image for Reinhard Neuwirth

Reinhard Neuwirth on May 15, 2026

‘Sort a List of Words, Longest First’: astounding how much work it is to get my home-made sorting function right. It is now 15 lines and still not achieving exactly what the 3-liner above does!

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on May 21, 2026

@Reinhard Neuwirth, that’s exactly the takeaway here 🙂 Implementing a correct, fast, and general-purpose sorting algorithm is really hard.

Quick heads-up: the exercise prompt asks you to use Python’s built-in sorting tools rather than write your own algorithm, so your 15-line version is going above and beyond. If you want to see fully working hand-rolled versions for comparison, classic implementations like selection sort, insertion sort, and merge sort are a good starting point. Our tutorial on Sorting Algorithms in Python walks you through several of them step by step.

Become a Member to join the conversation.