Canonicalize dotfile
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"].
Implement
canonical_lines(lines: list[str]) → list[str]Examples
in
[["b = 2","a=1","b=3"]]out["a=1","b=3"]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 10 min
solution.py
InputExpectedGot
[["b = 2","a=1","b=3"]]["a=1","b=3"]not run yetsample