Skip to content

Commit

Permalink
bpo-40651: Improve LRU recipe in the OrderedDict documentation (GH-#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
qudongfang committed May 18, 2020
1 parent 3a855b2 commit bb8635c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Doc/library/collections.rst
Expand Up @@ -1161,6 +1161,8 @@ variants of :func:`functools.lru_cache`::
return value

def __setitem__(self, key, value):
if key in self:
self.move_to_end(key)
super().__setitem__(key, value)
if len(self) > self.maxsize:
oldest = next(iter(self))
Expand Down

0 comments on commit bb8635c

Please sign in to comment.