Ten short Python functions from easy to tricky, each sent on its own and run against hidden tests. Three takes per question.
Rounds stay open: later videos added their new models to this one.
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.
===PART===
Write is_leap(year: int) -> bool to return whether year is a leap year in the Gregorian calendar.
===PART===
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 "".
===PART===
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.
===PART===
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 .
===PART===
Write . The string 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 . If a key repeats, use the last value. Return for an empty line.
===PART===
Write . The input intervals may be in any order. Merge intervals that overlap or touch, so and become . Return the merged intervals as tuples sorted by start, and leave the input list unchanged.
===PART===
Write to add calendar months to . may be negative. If the day does not exist in the target month, use the last day of that month.
===PART===
Write . A word is a maximal sequence of ASCII letters and apostrophes. Words compare case-insensitively and are returned in lowercase. Return the most frequent words as tuples, sorted by highest count first, breaking ties alphabetically by word.
===PART===
Write . Flatten nested dicts and lists into a single level, joining keys with and using list indices as keys. Keep an empty dict or empty list as the value at its key. returns .
===PART===
Write , a decorator factory that caches a function's results by its positional arguments without using or . It stores at most 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 .
Sorted by score, then cost. Open a row to load its answer.
"2.68"parse_kv(line: str) -> dict[str, str]line=c={}merge_intervals(intervals: list[tuple[int, int]]) -> list[tuple[int, int]](1, 2)(2, 3)(1, 3)add_months(d: datetime.date, months: int) -> datetime.datemonthsdmonthstop_k_words(text: str, k: int) -> list[tuple[str, int]]k(word, count)flatten(obj: dict, sep: str = ".") -> dictsepflatten({"a": {"b": 1}, "c": [{"d": 2}, 3], "e": {}}){"a.b": 1, "c.0.d": 2, "c.1": 3, "e": {}}lru(maxsize: int)functools.lru_cachefunctools.cachemaxsize__name__