Skip to content

Commit a70a8f3

Browse files
hulikaudonnemartin
authored andcommitted
Fix dict KeyError (donnemartin#153)
1 parent e50e200 commit a70a8f3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

solutions/object_oriented_design/lru_cache/lru_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get(self, query):
3434
3535
Accessing a node updates its position to the front of the LRU list.
3636
"""
37-
node = self.lookup[query]
37+
node = self.lookup.get(query)
3838
if node is None:
3939
return None
4040
self.linked_list.move_to_front(node)
@@ -47,7 +47,7 @@ def set(self, results, query):
4747
If the entry is new and the cache is at capacity, removes the oldest entry
4848
before the new entry is added.
4949
"""
50-
node = self.lookup[query]
50+
node = self.lookup.get(query)
5151
if node is not None:
5252
# Key exists in cache, update the value
5353
node.results = results

0 commit comments

Comments
 (0)