summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqudongfang <qudongfang@users.noreply.github.com>2020-05-18 03:50:51 (GMT)
committerGitHub <noreply@github.com>2020-05-18 03:50:51 (GMT)
commitbb8635cc3bc3dd65996803849ee1a91cfbebae9c (patch)
tree3e067b2201e69a2aa93470a9cbd8fe7f372fd3e2
parent3a855b26aed02abf87fc1163ad0d564dc3da1ea3 (diff)
downloadcpython-bb8635cc3bc3dd65996803849ee1a91cfbebae9c.zip
cpython-bb8635cc3bc3dd65996803849ee1a91cfbebae9c.tar.gz
cpython-bb8635cc3bc3dd65996803849ee1a91cfbebae9c.tar.bz2
bpo-40651: Improve LRU recipe in the OrderedDict documentation (GH-#20139)
-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 c9533a3..549ac1b 100644
--- a/Doc/library/collections.rst
+++ b/Doc/library/collections.rst
@@ -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))