LearnFrenzy
Sign in Take a free test

Lambda Functions · Predict the Output · Question 9

max() and min() with lambda keys on a dict Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 9 Back to Exercise

What is the output of the following Python program?

main.py
d = {"a": 3, "b": 7, "c": 5}
print(max(d, key=lambda k: d[k]), min(d.items(), key=lambda kv: kv[1]), max(d))
  • A b ('a', 3) c Correct
  • B 7 ('a', 3) c
  • C b ('a', 3) b
  • D c ('a', 3) c
Correct Answer: Option A

With a key, items are compared by their values. max(d) without a key compares the keys themselves: "c" is the largest letter.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links