From d88f0aa8e24ea7562f2e04833f46d8526e846334 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Wed, 20 May 2020 21:21:02 -0700 Subject: [PATCH] bpo-40651: Improve LRU recipe in the OrderedDict documentation (GH-GH-20139) (GH-20167) --- Doc/library/collections.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 8dcf9451d72..d4297166597 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))