Canonicalize dotfile

Write codeEasy10 min

Your task

To diff dotfiles across machines you first rewrite each file into a canonical form. Given the raw lines: trim each line, drop those that are empty or start with "#", and split the rest at the first "=" (trim the key and the value; a key assigned more than once keeps only its final value). Then print one "key=value" string per surviving key, no spaces around the "=", with the keys in ascending alphabetical order. Return that list. Example: ["b = 2", "a=1", "b=3"] becomes ["a=1", "b=3"].

Examples

canonical_lines(lines: list[str]) -> list[str]
Example 1
Inputcanonical_lines(["b = 2", "a=1", "b=3"])
Output["a=1", "b=3"]