From bb8635cc3bc3dd65996803849ee1a91cfbebae9c Mon Sep 17 00:00:00 2001 From: qudongfang Date: Mon, 18 May 2020 04:50:51 +0100 Subject: bpo-40651: Improve LRU recipe in the OrderedDict documentation (GH-#20139) --- Doc/library/collections.rst | 2 ++ 1 file changed, 2 insertions(+) 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)) -- cgit v0.12