r/learnpython • • Sep 08 '25

Explain This Code

students = {"Frank": 85, "Monica": 72, "Steve": 90} print(max(students, key=students.get))

Can you explain this code in simple terms or to 10 years old guy I can't understand this (key=students.get) Can you explain what is the purpose and use of (key=students.get) this.

0 Upvotes

12 comments sorted by

View all comments

4

u/LeskoIam Sep 08 '25

It will cal '.get' function on every member of the dict and use that for 'max' method. Because '.get' does not have parentheses ('.get()') it is not called at that line but when 'max()' is evaluated.