summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2020-05-21 04:21:02 (GMT)
committerGitHub <noreply@github.com>2020-05-21 04:21:02 (GMT)
commitd88f0aa8e24ea7562f2e04833f46d8526e846334 (patch)
treedda0c1c824ca2c801f70ed3f3b77b1bd6dcae4e7
parenta59fc9160db50a5e20358303e7ddbda180a1b74f (diff)
downloadcpython-d88f0aa8e24ea7562f2e04833f46d8526e846334.zip
cpython-d88f0aa8e24ea7562f2e04833f46d8526e846334.tar.gz
cpython-d88f0aa8e24ea7562f2e04833f46d8526e846334.tar.bz2
bpo-40651: Improve LRU recipe in the OrderedDict documentation (GH-GH-20139) (GH-20167)
-rw-r--r--Doc/library/collections.rst2
1 files changed, 2 insertions, 0 deletions
diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst
index 8dcf945..d429716 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -1150,6 +1150,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))