[Solved] PYTHON codes with a lesson from a book [closed]


Briefly:

  • cities is instantiated as a dictionary, and some key/value are inserted here. Both key and values are string for CA -> San Francisco, MI -> Detroit, etc. etc.

  • a function named find_city is defined, it takes two input parameters (themap and state);

  • to the cities dictionary is added another key/value, where key is the string ‘_find’ but, this time, the value is the function find_city and not a string as before;

  • in the line city_found = cities['_find'](cities, state) you ask to the dictionary cities the value associated to the key ‘_find’, that is the function find_city. Then, this function is called with the dictionary itself as first parameter and the ‘state’ read by the stdin as second parameter.

It would have been the same if it was written as:

method = cities['_find']
city_found = method(cities, state)

HTH

4

solved PYTHON codes with a lesson from a book [closed]