Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sorting a dictionary
#1
I have a dictionary like:
dic = {0: [('key1', 0.061),
  ('key2', 0.034),
  ('key3', 0.046),
  ('key4', 0.0593),
  ('key5', 0.091)],
 1: [('key1', 0.025),
  ('key2', 0.046),
  ('key3', 0.014),
  ('key4', 0.054),
  ('key5', 0.058)]
}
How can I sort this based on the float values of each keys.

This is not working:
for i in sorted(dic.values()):
     print(i)
Yoriz write Sep-13-2022, 05:29 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Sorting a dictionary - by v_mn - Sep-12-2022, 05:08 PM
RE: Sorting a dictionary - by deanhystad - Sep-12-2022, 06:43 PM
RE: Sorting a dictionary - by woooee - Sep-12-2022, 06:50 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sorting a copied list is also sorting the original list ? SN_YAZER 3 3,335 Apr-11-2019, 05:10 PM
Last Post: SN_YAZER

Forum Jump:

User Panel Messages

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