Python Forum
Writing a lambda function that sorts dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Writing a lambda function that sorts dictionary
#1
Hi guys! :)

dict1 = {'c':3, 'a':5, 'f':7, 'e':4}
Was wandering how to sort this dictionary by highest value first using lambda function?

expected result:
dict2 = {'f':7, 'a':5, 'e':4, 'c':3}
Appreciate the help !
Reply
#2
check https://stackoverflow.com/questions/6131...y-by-value
GJG likes this post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Function parameter not writing to variable Karp 5 891 Aug-07-2023, 05:58 PM
Last Post: Karp
  Add two resultant fields from python lambda function klllmmm 4 848 Jun-06-2023, 05:11 PM
Last Post: rajeshgk
  passing dictionary to the function mark588 2 931 Dec-19-2022, 07:28 PM
Last Post: deanhystad
  Create a function for writing to SQL data to csv mg24 4 1,110 Oct-01-2022, 04:30 AM
Last Post: mg24
  Writing into 2 text files from the same function paul18fr 4 1,628 Jul-28-2022, 04:34 AM
Last Post: ndc85430
  I am writing a car rental program on python. In this function I am trying to modify aboo 2 2,677 Aug-05-2021, 06:00 PM
Last Post: deanhystad
  2 Different Sorts in a Dataframe stylingpat 1 1,889 Apr-14-2021, 03:02 PM
Last Post: stylingpat
  Using Dictionary to Test Evenness of Distribution Generated by Randint Function new_coder_231013 6 3,198 Feb-23-2021, 01:29 PM
Last Post: new_coder_231013
  Writing a function to calculate time range in Unix Epoch Time t4keheart 2 2,929 Jul-15-2020, 01:55 AM
Last Post: t4keheart
  translating lambda in function fabs 1 2,121 Apr-28-2020, 05:18 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020