From: qudongfang Date: Mon, 18 May 2020 03:50:51 +0000 (+0100) Subject: bpo-40651: Improve LRU recipe in the OrderedDict documentation (GH-#20139) X-Git-Tag: v3.9.0b1~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bb8635cc3bc3dd65996803849ee1a91cfbebae9c;p=thirdparty%2FPython%2Fcpython.git bpo-40651: Improve LRU recipe in the OrderedDict documentation (GH-#20139) --- diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index c9533a3cb8f4..549ac1bccadf 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))