From caa54419fd16f26ef9ba317dc02c7ed84bcdffe1 Mon Sep 17 00:00:00 2001 From: qudongfang Date: Mon, 18 May 2020 04:50:51 +0100 Subject: [PATCH] bpo-40651: Improve LRU recipe in the OrderedDict documentation (GH-GH-20139) (cherry picked from commit bb8635cc3bc3dd65996803849ee1a91cfbebae9c) Co-authored-by: qudongfang --- Doc/library/collections.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 8dcf9451d72bfe..d4297166597b64 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))