Python Forum
get method within max function for a dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get method within max function for a dictionary
#1
I've been working on the Udacity python course, and in of the lessons I needed to take a dictionary of years and lists of names and make a list of the name(s) that appeared the greatest number of times. I was stuck until I found some code online, but I don't understand it and haven't been able to find any clarification as of yet.
The code is as follows:

most_appeared.append(max(mydict,key=mydict.get))
My trouble is with the second argument of max: key=mydict.get

Why doesn't get include the normal parenthesis at the end? How does this argument tell python to return the keys instead of the values? If someone could explain how this works it would be much appreciated.
Reply


Messages In This Thread
get method within max function for a dictionary - by Blanchdog - Jul-03-2020, 04:05 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to use value in dictionary as arguments in function gabejohnsonny21 6 3,740 Apr-22-2020, 04:53 PM
Last Post: deanhystad
  Why is this function printing the number of keys in a dictionary? mafr97 5 3,059 Sep-17-2019, 06:19 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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