Jul-03-2020, 04:05 AM
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:
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.
The code is as follows:
1 |
most_appeared.append( max (mydict,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.