Document style stack

Write codeEasy15 min

Your task

A document renderer walks a page of nested sections and reports what style is in force at each point. Each entry in events is one of three strings. "enter|font=serif" opens a section that binds one attribute, written as the attribute name, an equals sign, then the value. Neither the name nor the value contains a pipe or an equals sign. "leave" closes the innermost section still open, and does nothing when no section is open. "ask|font" asks what that attribute is right now, which is the value bound by the innermost section still open that binds it. Return the answers to the asks, in the order the asks appear, using the string "inherit" when no open section binds the attribute asked for.

Examples

resolve_scoped_styles(events: list[str]) -> list[str]
Example 1
Inputresolve_scoped_styles(["enter|font=serif", "ask|font", "leave", "ask|font"])
Output["serif", "inherit"]
Example 2
Inputresolve_scoped_styles(["enter|color=teal", "enter|color=rust", "ask|color", "leave", "ask|color"])
Output["rust", "teal"]
Example 3
Inputresolve_scoped_styles(["enter|font=mono", "ask|color", "ask|font"])
Output["inherit", "mono"]