bpo-40651: Improve LRU recipe in the OrderedDict documentation (GH-#20139)

This commit is contained in:
qudongfang 2020-05-18 04:50:51 +01:00 committed by GitHub
parent 3a855b26ae
commit bb8635cc3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 0 deletions

View File

@ -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))