Skip to content

Commit e5b6af1

Browse files
Fixed doc tests
1 parent 2c9d524 commit e5b6af1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Diff for: other/lru_cache_pythonic.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
'''
44
The following implementation of LRU Cache is one of the most elegant pythonic implementations.
5-
It only uses the in-built python dictionary. This works because
5+
It only uses the in-built python dictionary (https://docs.python.org/3/library/stdtypes.html#typesmapping). This works because
66
the Python dictionary maintains the order of insertion of keys and ensures O(1) operations on insert, delete and access.
77
'''
88
class LRUCache(dict):
@@ -17,6 +17,13 @@ def __init__(self, capacity : int):
1717
This method gets the value associated with the key.
1818
key : Hashable -> a hashable object that is mapped to a value inside of the LRU cache.
1919
returns -> value : Any -> any object that is stored as a value inside of the LRU cache.
20+
21+
>>> cache = LRUCache(2)
22+
>>> cache.put(1,1)
23+
>>> cache.get(1)
24+
1
25+
>>> cache.get(2)
26+
KeyError: '2 not found.'
2027
'''
2128
def get(self, key:Hashable)->Any:
2229
if key not in self:

0 commit comments

Comments
 (0)