Explorar o código

Fix dict KeyError (#152)

Anton Hulikau %!s(int64=7) %!d(string=hai) anos
pai
achega
e50e2007f6
Modificáronse 1 ficheiros con 2 adicións e 2 borrados
  1. 2 2
      solutions/object_oriented_design/lru_cache/lru_cache.ipynb

+ 2 - 2
solutions/object_oriented_design/lru_cache/lru_cache.ipynb

@@ -84,7 +84,7 @@
     "        \n",
     "        Accessing a node updates its position to the front of the LRU list.\n",
     "        \"\"\"\n",
-    "        node = self.lookup[query]\n",
+    "        node = self.lookup.get(query)\n",
     "        if node is None:\n",
     "            return None\n",
     "        self.linked_list.move_to_front(node)\n",
@@ -97,7 +97,7 @@
     "        If the entry is new and the cache is at capacity, removes the oldest entry\n",
     "        before the new entry is added.\n",
     "        \"\"\"\n",
-    "        node = self.lookup[query]\n",
+    "        node = self.lookup.get(query)\n",
     "        if node is not None:\n",
     "            # Key exists in cache, update the value\n",
     "            node.results = results\n",