Skip to content
Advertisement

Sort a list by value of a dict python

I need some help, how to use the algorithm selection sort to sort a list by the values of a dict. I wrote some code but I don’t know how continue, that the code work.

JavaScript

e.g. sort the list by the values of the dict

JavaScript

Advertisement

Answer

New Answer

  • Create class selection_sort which has get_sorted() method that will sort the list based on dictionary values using selection sort.
  • Here we compare two value and if first value is greater than second, than swap both the values. Repeat this step until entire list is sorted.

JavaScript

Test Case

  • Test which you have written is comparing L with Expected. It should compare actual with expected. self.assertEqual(L, expected)

  • Also, expected = ["March", "May", "December", "October", "September"] is incorrect. It should have been ["March", "May","September", "October", "December"]

JavaScript

Old Answer

Try this,

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement