[Tutor] Python Hard_way 40

Andre Engels andreengels at gmail.com
Wed May 11 17:44:48 CEST 2011


On Wed, May 11, 2011 at 5:24 PM, Robert . <forums at zhub.co.uk> wrote:
> Hi all,
>
> My first post ever! :)
> I'm following the guide "Learn Python the Hard Way" and have reached a point
> where I am struggling to understand the code and unfortunately the authors
> guide hasn't cleared it up for me. (excercise 40 for reference)
>
> The main confusion is coming from 'cities['_find'] = find_city' I'm not sure
> what this is really doing.
>
> From my learning, this should add an extra item to the dict with the index
> name of "_find" and the value which is returned from "find_city" function.

No, that would be
cities['_find'] = find_city()

When you use
cities['_find'] = find_city

the value of the extra item is _the function find_city itself_.

And thus later
city_found = cities['_find'](cities,state)

will be equivalent to
city_found = find_city(cities,state)

-- 
André Engels, andreengels at gmail.com


More information about the Tutor mailing list