You just look at two lines from your code:
cities['_find'] = find_citycity_found = cities['find'](cities, state)
Explanation for (1):
###Explanation for (1):
AsAs cities is dictionary before you use cities['_find'].
print it...
print(cities)
Output: {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville', 'NY': 'New York', 'OR': 'Portland'}
Now after using cities['_find']=find_city,
print(cities)
Output: {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville', 'NY': 'New York', 'OR': 'Portland', *'_find': <function find_city at 0x01BAB738*>}
Here the last dictionary item is added with key _find and the value is the function find_city.
###Explanation for (2):
Explanation for (2):
Now city_found = cities['find'](cities, state)
Now we know that find_city is in the dict at _find, that means we can do work with it. The it can be broken down like this:
Python sees
city_found =and knows we want to make a new variable.It then reads cities and finds that variable, it’s a dict.
Then there’s
['_find']which will index into the cities dict and pull out whatever is at_find.What is at
['_find']is our functionfind_cityso Python then knows it’s got a function, and it does the function call.The parameters cities, state are passed to this function
find_city, and it runs because it’s called.find_citythen tries to look up states inside cities, and returns what it finds.Python takes what
find_cityreturned, and finally that is what is assigned tocity_found.
You just look at two lines from your code:
cities['_find'] = find_citycity_found = cities['find'](cities, state)
###Explanation for (1):
As cities is dictionary before you use cities['_find'].
print it...
print(cities)
Output: {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville', 'NY': 'New York', 'OR': 'Portland'}
Now after using cities['_find']=find_city,
print(cities)
Output: {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville', 'NY': 'New York', 'OR': 'Portland', *'_find': <function find_city at 0x01BAB738*>}
Here the last dictionary item is added with key _find and the value is the function find_city.
###Explanation for (2):
Now city_found = cities['find'](cities, state)
Now we know that find_city is in the dict at _find, that means we can do work with it. The it can be broken down like this:
Python sees
city_found =and knows we want to make a new variable.It then reads cities and finds that variable, it’s a dict.
Then there’s
['_find']which will index into the cities dict and pull out whatever is at_find.What is at
['_find']is our functionfind_cityso Python then knows it’s got a function, and it does the function call.The parameters cities, state are passed to this function
find_city, and it runs because it’s called.find_citythen tries to look up states inside cities, and returns what it finds.Python takes what
find_cityreturned, and finally that is what is assigned tocity_found.
You just look at two lines from your code:
cities['_find'] = find_citycity_found = cities['find'](cities, state)
Explanation for (1):
As cities is dictionary before you use cities['_find'].
print it...
print(cities)
Output: {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville', 'NY': 'New York', 'OR': 'Portland'}
Now after using cities['_find']=find_city,
print(cities)
Output: {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville', 'NY': 'New York', 'OR': 'Portland', *'_find': <function find_city at 0x01BAB738*>}
Here the last dictionary item is added with key _find and the value is the function find_city.
Explanation for (2):
Now city_found = cities['find'](cities, state)
Now we know that find_city is in the dict at _find, that means we can do work with it. The it can be broken down like this:
Python sees
city_found =and knows we want to make a new variable.It then reads cities and finds that variable, it’s a dict.
Then there’s
['_find']which will index into the cities dict and pull out whatever is at_find.What is at
['_find']is our functionfind_cityso Python then knows it’s got a function, and it does the function call.The parameters cities, state are passed to this function
find_city, and it runs because it’s called.find_citythen tries to look up states inside cities, and returns what it finds.Python takes what
find_cityreturned, and finally that is what is assigned tocity_found.
- 2.5k
- 7
- 25
- 36
youYou just look at two lines from your code.
A)cities['_find'] = find_city:
B)city_found = cities['find'](cities, state)
cities['_find'] = find_citycity_found = cities['find'](cities, state)
Explanation###Explanation for A(1):-
As cities is dictionary before you use cities['_find']cities['_find'].
print it...
print(cities) ---> {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville', 'NY': 'New York', 'OR': 'Portland'}
print(cities)
Output: {'CA': 'San Francisco', Now'MI': after'Detroit', using'FL': 'Jacksonville', cities['_find']=find_city'NY': 'New York', 'OR': 'Portland'}
print(cities)
---> Now after using {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville', 'NY': 'New York', 'OR': 'Portland'cities['_find']=find_city,'_find': <function find_city at 0x01BAB738>}
print(cities) Here
Output: the{'CA': last'San dictionaryFrancisco', item'MI': is'Detroit', added'FL': with'Jacksonville', key'NY': "_find"'New andYork', the'OR': value'Portland', is*'_find': function<function find_city .Hopeat you0x01BAB738*>}
got now.
ExplanationHere the last dictionary item is added with key _find and the value is the function find_city.
###Explanation for B): Now city_found = cities['find'](cities, state2):
Now city_found = cities['find'](cities, state)
Now we know that find_city is in the dict at _find_find, that means we can do work with it. The it can be broken down like this:
Python sees city_found =
city_found =and knows we want to make a new variable.It then reads cities and finds that variable, it’s a dict.
Then there’s [’_find’]
['_find']which will index into the cities dict and pull out whatever is at _find_find.What is at [’_find’]
['_find']is our function find_cityfind_cityso Python then knows it’s got a function, and it does the function call.The parameters cities, state are passed to this function find_city
find_city, and it runs because it’s called.find_city
find_citythen tries to look up states inside cities, and returns what it finds.Python takes what find_city
find_cityreturned, and finally that is what is assigned to city_foundcity_found.
you just look at two lines from your code.
A)cities['_find'] = find_city
B)city_found = cities['find'](cities, state)
Explanation for A):- As cities is dictionary before you use cities['_find']. print it...
print(cities) ---> {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville', 'NY': 'New York', 'OR': 'Portland'}
Now after using cities['_find']=find_city ,
print(cities)
---> {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville', 'NY': 'New York', 'OR': 'Portland','_find': <function find_city at 0x01BAB738>}
Here the last dictionary item is added with key "_find" and the value is function find_city .Hope you got now.
Explanation for B): Now city_found = cities['find'](cities, state)
Now we know that find_city is in the dict at _find, that means we can do work with it. The it can be broken down like this:
Python sees city_found = and knows we want to make a new variable.
It then reads cities and finds that variable, it’s a dict.
Then there’s [’_find’] which will index into the cities dict and pull out whatever is at _find.
What is at [’_find’] is our function find_city so Python then knows it’s got a function, and it does the function call.
The parameters cities, state are passed to this function find_city, and it runs because it’s called.
find_city then tries to look up states inside cities, and returns what it finds.
Python takes what find_city returned, and finally that is what is assigned to city_found.
You just look at two lines from your code:
cities['_find'] = find_citycity_found = cities['find'](cities, state)
###Explanation for (1):
As cities is dictionary before you use cities['_find'].
print it...
print(cities)
Output: {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville', 'NY': 'New York', 'OR': 'Portland'}
Now after using cities['_find']=find_city,
print(cities)
Output: {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville', 'NY': 'New York', 'OR': 'Portland', *'_find': <function find_city at 0x01BAB738*>}
Here the last dictionary item is added with key _find and the value is the function find_city.
###Explanation for (2):
Now city_found = cities['find'](cities, state)
Now we know that find_city is in the dict at _find, that means we can do work with it. The it can be broken down like this:
Python sees
city_found =and knows we want to make a new variable.It then reads cities and finds that variable, it’s a dict.
Then there’s
['_find']which will index into the cities dict and pull out whatever is at_find.What is at
['_find']is our functionfind_cityso Python then knows it’s got a function, and it does the function call.The parameters cities, state are passed to this function
find_city, and it runs because it’s called.find_citythen tries to look up states inside cities, and returns what it finds.Python takes what
find_cityreturned, and finally that is what is assigned tocity_found.
you just look at two lines from your code.
A)cities['_find'] = find_city
B)city_found = cities['find'](cities, state)
Explanation for A):- As cities is dictionary before you use cities['_find']. print it...
print(cities) ---> {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville', 'NY': 'New York', 'OR': 'Portland'}
Now after using cities['_find']=find_city ,
print(cities)
---> {'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville', 'NY': 'New York', 'OR': 'Portland', '_find': <function find_city at 0x01BAB738>}
Here the last dictionary item is added with key "_find" and the value is function find_city .Hope you got now.
Explanation for B): Now city_found = cities['find'](cities, state)
Now we know that find_city is in the dict at _find, that means we can do work with it. The it can be broken down like this:
Python sees city_found = and knows we want to make a new variable.
It then reads cities and finds that variable, it’s a dict.
Then there’s [’_find’] which will index into the cities dict and pull out whatever is at _find.
What is at [’_find’] is our function find_city so Python then knows it’s got a function, and it does the function call.
The parameters cities, state are passed to this function find_city, and it runs because it’s called.
find_city then tries to look up states inside cities, and returns what it finds.
Python takes what find_city returned, and finally that is what is assigned to city_found.