From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Thu, 21 May 2020 04:21:02 +0000 (-0700) Subject: bpo-40651: Improve LRU recipe in the OrderedDict documentation (GH-GH-20139) (GH... X-Git-Tag: v3.8.4rc1~105 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d88f0aa8e24ea7562f2e04833f46d8526e846334;p=thirdparty%2FPython%2Fcpython.git bpo-40651: Improve LRU recipe in the OrderedDict documentation (GH-GH-20139) (GH-20167) --- diff --git a/Doc/library/collections.rst b/Doc/library/collections.rst index 8dcf9451d72b..d4297166597b 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))