[Tutor] Python functions are first-class citizens

memilanuk memilanuk at gmail.com
Fri Aug 1 09:31:42 CEST 2014


On 07/31/2014 11:46 PM, Ben Finney wrote:

> The ‘max’ function can be told how to determine the ordering of items,
> by specifying a key parameter. The parameter is specified by giving a
> value; that value is a function.

Hmmm... might just have had a break-thru here: so max() iterates thru 
counts, which because its the only non-keyword argument provided has to 
be an iterable (if I'm reading this correctly:
https://docs.python.org/3/library/functions.html?highlight=max#max). It 
takes each dict key ('a', 'b', 'c'), feeds them in turn to counts.get() 
like so: counts.get('a'), counts.get('b'), counts.get('c'), which should 
return the corresponding dict values (1, 22, 100), and then max() 
returns the highest value seen.

Is that about right?

Monte

-- 
Shiny!  Let's be bad guys.

Reach me @ memilanuk (at) gmail dot com



More information about the Tutor mailing list