I can't understand the magic happening in helpers.py What is lookup.cache[]? I know lookup is the name of our function. I tried to search online for cache function but couldn't get any leads. I need to understand it to rectify my pset. It shows too many news results when a marker is clicked. Help! enter image description here


lookup.cache is a dictionary. It is used to store all news articles that already have been looked up earlier for that zipcode.

The reason to do this is twofold:

  • It makes the application faster
  • It reduces the amount of network traffic

Disadvantage of this approach:

  • If you leave the application running over some longer period of time, you won't see the most recent news articles.

About your second question:

You will have to arrange that somehow in application.py.

You will often receive lots of news articles. If you only want to show 5 of them, make sure you only show 5.

And finally, to quote Cliff B:

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • Yes. lookup.cache is a dict. But it's declaration looks different. Is cache a unique function acting on dicts? Also, the dict was never initialized before. It messes up with my concept of dict.
    – pankaj
    Oct 27 '18 at 9:49
  • Is caching happening automatically & we are just refering it? This was intention was my question.
    – pankaj
    Oct 27 '18 at 9:51
  • The line lookup.cache = {} creates an empty directory. The line lookup.cache[geo] = ... simply assigns a value into the dictionary for the key geo. That value happens to be a list. Oct 27 '18 at 10:10
  • And finally, the list is created using List Comprehension. See docs.python.org/3/tutorial/… Oct 27 '18 at 10:11
  • Oh, my bad. I am not very fluent with these lists. Thank you! This answers all my questions.
    – pankaj
    Oct 27 '18 at 10:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .