Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write is_leap(year: int) -> bool to return whether year is a leap year in the Gregorian calendar.
def is_leap(year: int) -> bool:
return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write is_leap(year: int) -> bool to return whether year is a leap year in the Gregorian calendar.
def is_leap(year: int) -> bool:
return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write is_leap(year: int) -> bool to return whether year is a leap year in the Gregorian calendar.
def is_leap(year: int) -> bool:
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write rle(s: str) -> str to perform run-length encoding on s. Replace each run of consecutive identical characters with that character followed by the run length. rle("aaabcc") returns "a3b1c2" and rle("") returns "".
def rle(s: str) -> str:
if not s:
return ""
result = []
prev = s[0]
count = 1
for ch in s[1:]:
if ch == prev:
count += 1
else:
result.append(f"{prev}{count}")
prev = ch
count = 1
result.append(f"{prev}{count}")
return "".join(result)
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write rle(s: str) -> str to perform run-length encoding on s. Replace each run of consecutive identical characters with that character followed by the run length. rle("aaabcc") returns "a3b1c2" and rle("") returns "".
def rle(s: str) -> str:
if not s:
return ""
result = []
prev = s[0]
count = 1
for ch in s[1:]:
if ch == prev:
count += 1
else:
result.append(f"{prev}{count}")
prev = ch
count = 1
result.append(f"{prev}{count}")
return "".join(result)
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write rle(s: str) -> str to perform run-length encoding on s. Replace each run of consecutive identical characters with that character followed by the run length. rle("aaabcc") returns "a3b1c2" and rle("") returns "".
def rle(s: str) -> str:
if not s:
return ""
result = []
count = 1
for i in range(1, len(s)):
if s[i] == s[i - 1]:
count += 1
else:
result.append(s[i - 1] + str(count))
count = 1
result.append(s[-1] + str(count))
return "".join(result)
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write chunks(items, n: int) -> list[list]. items is an iterable, which may be a generator. Return consecutive lists of n elements, where the last list may be shorter. Raise ValueError when n is less than 1.
def chunks(items, n: int) -> list[list]:
if n < 1:
raise ValueError("n must be at least 1")
result = []
chunk = []
for item in items:
chunk.append(item)
if len(chunk) == n:
result.append(chunk)
chunk = []
if chunk:
result.append(chunk)
return result
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write chunks(items, n: int) -> list[list]. items is an iterable, which may be a generator. Return consecutive lists of n elements, where the last list may be shorter. Raise ValueError when n is less than 1.
def chunks(items, n: int) -> list[list]:
if n < 1:
raise ValueError("n must be at least 1")
result = []
current = []
for item in items:
current.append(item)
if len(current) == n:
result.append(current)
current = []
if current:
result.append(current)
return result
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write chunks(items, n: int) -> list[list]. items is an iterable, which may be a generator. Return consecutive lists of n elements, where the last list may be shorter. Raise ValueError when n is less than 1.
def chunks(items, n: int) -> list[list]:
if n < 1:
raise ValueError("n must be at least 1")
result = []
chunk = []
for item in items:
chunk.append(item)
if len(chunk) == n:
result.append(chunk)
chunk = []
if chunk:
result.append(chunk)
return result
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write round_half_up(value: str, digits: int) -> str. The string value represents a decimal number. Round it to digits decimal places, rounding exact ties away from zero based on the exact value written in value. Return a string with exactly digits decimal places, and omit the decimal point when digits is 0. round_half_up("2.675", 2) returns "2.68".
def round_half_up(value: str, digits: int) -> str:
from decimal import Decimal, ROUND_HALF_UP, getcontext
getcontext().prec = 500
d = Decimal(value)
if digits < 0:
# Rounding to a negative number of decimal places means rounding to tens, hundreds, etc.
# We need to handle this by shifting, rounding, then shifting back.
shift = 10 ** (-digits)
# Multiply by shift, round to 0 places, divide by shift
d = d * shift
# Round to 0 places using ROUND_HALF_UP
d = d.quantize(Decimal('1'), rounding=ROUND_HALF_UP)
d = d / shift
# Now format with 0 decimal places
result = format(d, 'f')
return result
else:
quantum = Decimal(1).scaleb(-digits)
d = d.quantize(quantum, rounding=ROUND_HALF_UP)
result = format(d, 'f')
# Ensure exactly `digits` decimal places
if '.' in result:
int_part, frac_part = result.split('.')
frac_part = frac_part[:digits]
if len(frac_part) < digits:
frac_part = frac_part + '0' * (digits - len(frac_part))
return int_part + '.' + frac_part
else:
return result + '.' + '0' * digits
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write round_half_up(value: str, digits: int) -> str. The string value represents a decimal number. Round it to digits decimal places, rounding exact ties away from zero based on the exact value written in value. Return a string with exactly digits decimal places, and omit the decimal point when digits is 0. round_half_up("2.675", 2) returns "2.68".
def round_half_up(value: str, digits: int) -> str:
from decimal import Decimal, ROUND_HALF_UP, getcontext
getcontext().prec = 1000
d = Decimal(value)
if digits < 0:
digits = 0
quantize_str = '1' + '0' * digits if digits > 0 else '1'
q = Decimal(quantize_str).scaleb(-digits) if digits > 0 else Decimal(1)
# Actually simpler: use Decimal(1).scaleb(-digits)
if digits == 0:
q = Decimal(1)
else:
q = Decimal(1).scaleb(-digits)
rounded = d.quantize(q, rounding=ROUND_HALF_UP)
if digits == 0:
return str(rounded)
else:
# Format to exactly `digits` decimal places
s = str(rounded)
if '.' in s:
integer_part, fractional_part = s.split('.')
fractional_part = fractional_part.ljust(digits, '0')[:digits]
return integer_part + '.' + fractional_part
else:
return s + '.' + '0' * digits
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write round_half_up(value: str, digits: int) -> str. The string value represents a decimal number. Round it to digits decimal places, rounding exact ties away from zero based on the exact value written in value. Return a string with exactly digits decimal places, and omit the decimal point when digits is 0. round_half_up("2.675", 2) returns "2.68".
def round_half_up(value: str, digits: int) -> str:
from decimal import Decimal, ROUND_HALF_UP, getcontext
getcontext().prec = max(len(value), 10)
d = Decimal(value)
quantize_exp = Decimal(1).scaleb(-digits)
rounded = d.quantize(quantize_exp, rounding=ROUND_HALF_UP)
if digits == 0:
return str(int(rounded))
else:
return str(rounded)
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write parse_kv(line: str) -> dict[str, str]. The string line contains key=value pairs separated by one or more spaces. A value may be enclosed in double quotes; if so, it may contain spaces and =, and the quotes are not included in the parsed value. A value may be empty, as in c=. If a key repeats, use the last value. Return {} for an empty line.
import re
def parse_kv(line: str) -> dict[str, str]:
if not line.strip():
return {}
result: dict[str, str] = {}
# Match key=value pairs where:
# - key: one or more non-space characters
# - =
# - value: either a quoted string (possibly containing spaces and =) or an unquoted non-space sequence (possibly empty)
pattern = re.compile(
r'(\S+)=("((?:[^"\\]|\\.)*)"|(\S*))'
)
for match in pattern.finditer(line):
key = match.group(1)
if match.group(2) is not None:
# Quoted value
value = match.group(3)
else:
# Unquoted value (may be empty)
value = match.group(5) or ""
result[key] = value
return result
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write parse_kv(line: str) -> dict[str, str]. The string line contains key=value pairs separated by one or more spaces. A value may be enclosed in double quotes; if so, it may contain spaces and =, and the quotes are not included in the parsed value. A value may be empty, as in c=. If a key repeats, use the last value. Return {} for an empty line.
import re
def parse_kv(line: str) -> dict[str, str]:
if not line.strip():
return {}
result: dict[str, str] = {}
# Match key=value or key="value with spaces"
# Key: non-whitespace characters (at least one)
# Value: either quoted (double quotes, may contain spaces and =) or unquoted (non-space characters, possibly empty)
pattern = re.compile(r'(\S+)=(?:"([^"]*)"|(\S*)|)')
for match in pattern.finditer(line):
key = match.group(1)
quoted_value = match.group(2)
unquoted_value = match.group(3)
if quoted_value is not None:
value = quoted_value
else:
value = unquoted_value if unquoted_value is not None else ""
result[key] = value
return result
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write parse_kv(line: str) -> dict[str, str]. The string line contains key=value pairs separated by one or more spaces. A value may be enclosed in double quotes; if so, it may contain spaces and =, and the quotes are not included in the parsed value. A value may be empty, as in c=. If a key repeats, use the last value. Return {} for an empty line.
import re
def parse_kv(line: str) -> dict[str, str]:
if not line.strip():
return {}
result: dict[str, str] = {}
# Pattern: key = value, where value is either quoted (with possible spaces and =) or unquoted (no spaces)
# Key: one or more non-space, non-equals characters
# Value: either "..." (double-quoted, can contain spaces and =) or unquoted (non-space characters)
pattern = re.compile(r'(\S+?)=(?:"((?:[^"\\]|\\.)*)"|(\S*))')
for match in pattern.finditer(line):
key = match.group(1)
if match.group(2) is not None:
value = match.group(2)
else:
value = match.group(3)
result[key] = value
return result
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write merge_intervals(intervals: list[tuple[int, int]]) -> list[tuple[int, int]]. The input intervals may be in any order. Merge intervals that overlap or touch, so (1, 2) and (2, 3) become (1, 3). Return the merged intervals as tuples sorted by start, and leave the input list unchanged.
def merge_intervals(intervals: list[tuple[int, int]]) -> list[tuple[int, int]]:
if not intervals:
return []
sorted_intervals = sorted(intervals, key=lambda x: x[0])
merged = [list(sorted_intervals[0])]
for current in sorted_intervals[1:]:
last = merged[-1]
if current[0] <= last[1]:
last[1] = max(last[1], current[1])
else:
merged.append(list(current))
return [(start, end) for start, end in merged]
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write merge_intervals(intervals: list[tuple[int, int]]) -> list[tuple[int, int]]. The input intervals may be in any order. Merge intervals that overlap or touch, so (1, 2) and (2, 3) become (1, 3). Return the merged intervals as tuples sorted by start, and leave the input list unchanged.
def merge_intervals(intervals: list[tuple[int, int]]) -> list[tuple[int, int]]:
if not intervals:
return []
sorted_intervals = sorted(intervals, key=lambda x: x[0])
merged = [list(sorted_intervals[0])]
for start, end in sorted_intervals[1:]:
if start <= merged[-1][1]:
merged[-1][1] = max(merged[-1][1], end)
else:
merged.append([start, end])
return [(s, e) for s, e in merged]
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write merge_intervals(intervals: list[tuple[int, int]]) -> list[tuple[int, int]]. The input intervals may be in any order. Merge intervals that overlap or touch, so (1, 2) and (2, 3) become (1, 3). Return the merged intervals as tuples sorted by start, and leave the input list unchanged.
def merge_intervals(intervals: list[tuple[int, int]]) -> list[tuple[int, int]]:
if not intervals:
return []
sorted_intervals = sorted(intervals, key=lambda x: x[0])
merged = [list(sorted_intervals[0])]
for start, end in sorted_intervals[1:]:
if start <= merged[-1][1]:
merged[-1][1] = max(merged[-1][1], end)
else:
merged.append([start, end])
return [tuple(interval) for interval in merged]
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write add_months(d: datetime.date, months: int) -> datetime.date to add months calendar months to d. months may be negative. If the day does not exist in the target month, use the last day of that month.
import datetime
import calendar
def add_months(d: datetime.date, months: int) -> datetime.date:
total_months = d.year * 12 + (d.month - 1) + months
year, month = divmod(total_months, 12)
month += 1
if month == 0:
month = 12
year -= 1
last_day = calendar.monthrange(year, month)[1]
day = min(d.day, last_day)
return datetime.date(year, month, day)
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write add_months(d: datetime.date, months: int) -> datetime.date to add months calendar months to d. months may be negative. If the day does not exist in the target month, use the last day of that month.
import datetime
import calendar
def add_months(d: datetime.date, months: int) -> datetime.date:
total_months = d.year * 12 + (d.month - 1) + months
year = total_months // 12
month = total_months % 12 + 1
if year < 0:
year += 1
month -= 12
last_day = calendar.monthrange(year, month)[1]
day = min(d.day, last_day)
return datetime.date(year, month, day)
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write add_months(d: datetime.date, months: int) -> datetime.date to add months calendar months to d. months may be negative. If the day does not exist in the target month, use the last day of that month.
import datetime
import calendar
def add_months(d: datetime.date, months: int) -> datetime.date:
total_months = d.month - 1 + months
year = d.year + total_months // 12
month = total_months % 12 + 1
if month < 1:
month += 12
year -= 1
elif month > 12:
month -= 12
year += 1
last_day = calendar.monthrange(year, month)[1]
day = min(d.day, last_day)
return datetime.date(year, month, day)
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write top_k_words(text: str, k: int) -> list[tuple[str, int]]. A word is a maximal sequence of ASCII letters and apostrophes. Words compare case-insensitively and are returned in lowercase. Return the k most frequent words as (word, count) tuples, sorted by highest count first, breaking ties alphabetically by word.
import re
from collections import Counter
def top_k_words(text: str, k: int) -> list[tuple[str, int]]:
words = re.findall(r"[a-zA-Z']+", text)
lower_words = [w.lower() for w in words]
counts = Counter(lower_words)
sorted_words = sorted(counts.items(), key=lambda x: (-x[1], x[0]))
return sorted_words[:k]
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write top_k_words(text: str, k: int) -> list[tuple[str, int]]. A word is a maximal sequence of ASCII letters and apostrophes. Words compare case-insensitively and are returned in lowercase. Return the k most frequent words as (word, count) tuples, sorted by highest count first, breaking ties alphabetically by word.
import re
from collections import Counter
def top_k_words(text: str, k: int) -> list[tuple[str, int]]:
# A word is a maximal sequence of ASCII letters and apostrophes
words = re.findall(r"[A-Za-z']+", text)
lower_words = [w.lower() for w in words]
counts = Counter(lower_words)
# Sort by count descending, then word alphabetically
sorted_words = sorted(counts.items(), key=lambda x: (-x[1], x[0]))
return sorted_words[:k]
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write top_k_words(text: str, k: int) -> list[tuple[str, int]]. A word is a maximal sequence of ASCII letters and apostrophes. Words compare case-insensitively and are returned in lowercase. Return the k most frequent words as (word, count) tuples, sorted by highest count first, breaking ties alphabetically by word.
import re
from collections import Counter
def top_k_words(text: str, k: int) -> list[tuple[str, int]]:
# A word is a maximal sequence of ASCII letters and apostrophes
words = re.findall(r"[A-Za-z']+", text)
# Convert to lowercase for case-insensitive comparison
lower_words = [w.lower() for w in words]
counts = Counter(lower_words)
# Sort by highest count first, then alphabetically by word
sorted_words = sorted(counts.items(), key=lambda item: (-item[1], item[0]))
return sorted_words[:k]
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write flatten(obj: dict, sep: str = ".") -> dict. Flatten nested dicts and lists into a single level, joining keys with sep and using list indices as keys. Keep an empty dict or empty list as the value at its key. flatten({"a": {"b": 1}, "c": [{"d": 2}, 3], "e": {}}) returns {"a.b": 1, "c.0.d": 2, "c.1": 3, "e": {}}.
def flatten(obj: dict, sep: str = ".") -> dict:
result = {}
def _flatten(prefix: str, value) -> None:
if isinstance(value, dict):
if not value:
result[prefix] = value
else:
for k, v in value.items():
new_key = f"{prefix}{sep}{k}" if prefix else str(k)
_flatten(new_key, v)
elif isinstance(value, list):
if not value:
result[prefix] = value
else:
for i, v in enumerate(value):
new_key = f"{prefix}{sep}{i}" if prefix else str(i)
_flatten(new_key, v)
else:
result[prefix] = value
for k, v in obj.items():
_flatten(str(k), v)
return result
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write flatten(obj: dict, sep: str = ".") -> dict. Flatten nested dicts and lists into a single level, joining keys with sep and using list indices as keys. Keep an empty dict or empty list as the value at its key. flatten({"a": {"b": 1}, "c": [{"d": 2}, 3], "e": {}}) returns {"a.b": 1, "c.0.d": 2, "c.1": 3, "e": {}}.
def flatten(obj: dict, sep: str = ".") -> dict:
result = {}
def _flatten(prefix: str, value) -> None:
if isinstance(value, dict):
if not value:
if prefix:
result[prefix] = {}
else:
# Empty dict at top level; but obj is a dict, so this case
# is handled by the caller. We'll handle it in the main loop.
pass
else:
for k, v in value.items():
key = f"{prefix}{sep}{k}" if prefix else str(k)
_flatten(key, v)
elif isinstance(value, list):
if not value:
if prefix:
result[prefix] = []
else:
pass
else:
for i, v in enumerate(value):
key = f"{prefix}{sep}{i}" if prefix else str(i)
_flatten(key, v)
else:
if prefix:
result[prefix] = value
for k, v in obj.items():
if isinstance(v, dict) and not v:
result[str(k)] = {}
elif isinstance(v, list) and not v:
result[str(k)] = []
else:
_flatten(str(k), v)
return result
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write flatten(obj: dict, sep: str = ".") -> dict. Flatten nested dicts and lists into a single level, joining keys with sep and using list indices as keys. Keep an empty dict or empty list as the value at its key. flatten({"a": {"b": 1}, "c": [{"d": 2}, 3], "e": {}}) returns {"a.b": 1, "c.0.d": 2, "c.1": 3, "e": {}}.
def flatten(obj: dict, sep: str = ".") -> dict:
result = {}
def _flatten(current, prefix):
if isinstance(current, dict):
if not current:
if prefix:
result[prefix] = {}
return
for key, value in current.items():
new_key = f"{prefix}{sep}{key}" if prefix else str(key)
_flatten(value, new_key)
elif isinstance(current, list):
if not current:
if prefix:
result[prefix] = []
return
for index, value in enumerate(current):
new_key = f"{prefix}{sep}{index}" if prefix else str(index)
_flatten(value, new_key)
else:
result[prefix] = current
for key, value in obj.items():
_flatten(value, str(key))
return result
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write lru(maxsize: int), a decorator factory that caches a function's results by its positional arguments without using functools.lru_cache or functools.cache. It stores at most maxsize results. When the cache is full, evict the least recently used result. A cache hit counts as a use. The decorated function must preserve its original __name__.
from collections import OrderedDict
def lru(maxsize: int):
def decorator(func):
cache = OrderedDict()
def wrapper(*args):
key = args
if key in cache:
cache.move_to_end(key)
return cache[key]
result = func(*args)
cache[key] = result
if len(cache) > maxsize:
cache.popitem(last=False)
return result
wrapper.__name__ = func.__name__
return wrapper
return decorator
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write lru(maxsize: int), a decorator factory that caches a function's results by its positional arguments without using functools.lru_cache or functools.cache. It stores at most maxsize results. When the cache is full, evict the least recently used result. A cache hit counts as a use. The decorated function must preserve its original __name__.
import functools
from collections import OrderedDict
def lru(maxsize: int):
def decorator(func):
cache: OrderedDict = OrderedDict()
@functools.wraps(func)
def wrapper(*args, **kwargs):
key = args
if key in cache:
# Move to end to mark as most recently used
cache.move_to_end(key)
return cache[key]
result = func(*args, **kwargs)
cache[key] = result
if len(cache) > maxsize:
cache.popitem(last=False)
return result
return wrapper
return decorator
Write Python 3.13 code. Answer with one ```python code block that defines the function described below. Use only the standard library. Do not include explanations, examples, tests, input() calls, or print() calls.
Write lru(maxsize: int), a decorator factory that caches a function's results by its positional arguments without using functools.lru_cache or functools.cache. It stores at most maxsize results. When the cache is full, evict the least recently used result. A cache hit counts as a use. The decorated function must preserve its original __name__.
from collections import OrderedDict
import functools
def lru(maxsize: int):
def decorator(func):
cache = OrderedDict()
@functools.wraps(func)
def wrapper(*args, **kwargs):
key = args
if key in cache:
cache.move_to_end(key)
return cache[key]
result = func(*args, **kwargs)
cache[key] = result
if len(cache) > maxsize:
cache.popitem(last=False)
return result
return wrapper
return decorator