소스 검색

Fix dict KeyError (#153)

Anton Hulikau 7 년 전
부모
커밋
a70a8f3a04
1개의 변경된 파일2개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 2
      solutions/object_oriented_design/lru_cache/lru_cache.py

+ 2 - 2
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