From a70a8f3a04c3b51cade0b8de2b43de545f6e9471 Mon Sep 17 00:00:00 2001 From: Anton Hulikau Date: Thu, 26 Apr 2018 04:22:26 +0300 Subject: [PATCH] Fix dict KeyError (#153) --- solutions/object_oriented_design/lru_cache/lru_cache.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/solutions/object_oriented_design/lru_cache/lru_cache.py b/solutions/object_oriented_design/lru_cache/lru_cache.py index 75fe44d..acee465 100644 --- a/solutions/object_oriented_design/lru_cache/lru_cache.py +++ b/solutions/object_oriented_design/lru_cache/lru_cache.py @@ -34,7 +34,7 @@ class Cache(object): 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) @@ -47,7 +47,7 @@ class Cache(object): 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