Parse comma-separated list

Write codeEasy10 min

Your task

A rollout script needs the target machines from a config file. Lines look like "key=value" after trimming; ignore blank lines, "#" comment lines, and lines lacking "=". The key is the text before the first "=" with surrounding spaces removed; if the file assigns the requested key several times, only the FINAL assignment counts. Its value is a comma-separated list: split on every comma, trim each piece, and throw away pieces that are empty after trimming. Return the pieces in the order written. If the key never appears, return an empty list.

Examples

expand_host_list(lines: list[str], key: str) -> list[str]
Example 1
Inputexpand_host_list(["hosts=a.example, b.example ,c.example"], "hosts")
Output["a.example", "b.example", "c.example"]