Sorting strings vs. integers in Python

Опубликовано: 14 Февраль 2022
на канале: Python and Pandas with Reuven Lerner
3,124
67

Sorting follows fairly simple rules in Python, but they can sometimes lead to confusing results. For example, if you try to sort a list of strings, where the strings contain only digits, you might be rather surprised by the results. In this video, I explain what's going on, why sorting works the way it does, and how you can solve the problem using either list comprehension or the "key" parameter for sorted.

My Jupyter notebook (for this, and all videos) is available https://github.com/reuven/youTube-not.... And don't forget my free, weekly articles about Python at https://BetterDevelopersWeekly.com/!