Python Programming: Lesson 49 - Sortable Objects

Pubblicato il: 29 settembre 2021
sul canale di: 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!!!


In questa pagina del sito puoi guardare il video online Python Programming: Lesson 49 - Sortable Objects della durata di ore minuti seconda in buona qualità , che l'utente ha caricato youmils03 29 settembre 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 69 volte e gli è piaciuto 0 spettatori. Buona visione!