Back to Lesson

Sorting Dict Items by Value

Iterate upon a dictionary sequenced by its values.

Instructions

  • You have
    scores = {"Eve": 85, "Alice": 95, "Bob": 75}
    .
  • You want to print the names ordered by score, highest to lowest.
  • Use
    sorted(scores.items(), key=lambda item: item[1], reverse=True)
    to get a list of tuples.
  • Write a loop to print just the keys (the names) derived from the sorted structure in order.
main.py
main.py