Skip to content

Commit

Permalink
Fix dict KeyError (donnemartin#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
hulikau authored and donnemartin committed Apr 26, 2018
1 parent e50e200 commit a70a8f3
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions solutions/object_oriented_design/lru_cache/lru_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get(self, query):
Accessing a node updates its position to the front of the LRU list.
"""
node = self.lookup[query]
node = self.lookup.get(query)
if node is None:
return None
self.linked_list.move_to_front(node)
Expand All @@ -47,7 +47,7 @@ def set(self, results, query):
If the entry is new and the cache is at capacity, removes the oldest entry
before the new entry is added.
"""
node = self.lookup[query]
node = self.lookup.get(query)
if node is not None:
# Key exists in cache, update the value
node.results = results
Expand Down

0 comments on commit a70a8f3

Please sign in to comment.