Python Programming 13. Sorting a List

preview_player
Показать описание
This is the 13th in a course of computer science video lessons introducing programming with Python. This lesson follows on from the previous two lessons which introduced Python lists and how to iterate through a list using a loop. In this lesson you will learn how to sort a Python list. You will learn that this is easily done with the so called sort method, which will replace the existing list with a new sorted version of the list. You will also learn how to use the so called sorted method to sort a list, which leaves the original list unchanged, and generates a new list which is a sorted version of the original list. You will also learn how to sort a list into reverse order using the reverse parameter of the sort method. This lesson mentions the underlying algorithm of the Python sort method, namely, the Timsort which was invented by a computer scientist called Tim Peters. The Timsort first analyses the list to decide how best to sort it. Then, depending on the amount of data and the extent to which the list is already sorted, it employs either an insertion sort algorithm or a combination of the insertion sort and the merge sort.
Рекомендации по теме
Комментарии
Автор

You're an awesome teacher! I simply cannot find someone else like you on YouTube! I'm an embedded SW engineer and every time I open a video of yours, I learn so much! Thank you very much! :D

kavorka
Автор

If you are in a situation where you are iterating over an unsorted list, and checking a condition per element of that list in order to do something, then it is a good idea to sort that list beforehand using that condition, and then iterate through and compute without any branching.

adammzowh