Python Programming: Lesson 49 - Sortable Objects

Опубликовано: 29 Сентябрь 2021
на канале: youmils03
69
0

PLEASE SUBSCRIBE!!!

In the previous lesson (   • Python Programming: Lesson 48 - Bubble Sort  ), we gained exposure to a new algorithm called bubble sort. This is a relatively inefficient but easy-to-understand approach to sorting the elements in a list of SORTABLE elements. In this video, we spend some time reviewing bubble sort, but we do it in the context of generally sortable objects (instances of the Person class) rather than with ints or floats. In the next video, we will study insertion sort and selection sort from an object-oriented perspective.

Recall that we can use the _lt_ magic method to define what it means for one instance of a class to be less than another instance of a class. This is essentially when we attempt to sort a collection of elements that belong to a particular class. Try using bubble sort to sort a collection of Person objects, or Car objects, or Hamburger objects. How do you define __lt__? How do you code bubble sort? (See the previous video:    • Python Programming: Lesson 48 - Bubble Sort  )

2:07 Review of Lambda Functions and the del Keyword
6:55 Review of the pass Keyword
8:20 Review of Bubble Sort
12:16 NEW: Sortable Objects with the _lt_ Magic Method

Using _lt_ to compare instances of a class is kinda like using the compareTo( ) method in Java:    • Java Programming: Lesson 36 - Modified Con...  

Ready for another sorting algorithm called insertion sort? Check it out here:    • Python Programming: Lesson 50 - Insertion ...  

Thanks for watching, and PLEASE SUBSCRIBE!!!


На этой странице сайта вы можете посмотреть видео онлайн Python Programming: Lesson 49 - Sortable Objects длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь youmils03 29 Сентябрь 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 69 раз и оно понравилось 0 зрителям. Приятного просмотра!