Python Programming: Lesson 49 - Sortable Objects

Veröffentlicht am: 29 September 2021
auf dem Kanal: 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!!!


Auf dieser Seite können Sie das Online-Video Python Programming: Lesson 49 - Sortable Objects mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer youmils03 29 September 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 69 Mal angesehen und es wurde von 0 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!