Count section names

Write codeEasy12 min

Your task

An audit script summarizes a sectioned settings file. Trimmed lines of the shape "[title]" begin a section (title trimmed; the same title may begin sections in several places, they pool together). "name=data" lines (first "=", both sides trimmed) add the name to whatever section is open; names appearing before any section pool under the empty-string section, which exists in the output only if it actually received a name. Empty lines and "#" lines add nothing, yet a section title still counts even when nothing follows it. Report each section mapped to how many DISTINCT names it holds.

Examples

section_key_counts(lines: list[str]) -> dict[str,int]
Example 1
Inputsection_key_counts(["[app]", "name=x", "name=y", "port=1", "[db]"])
Output{"app": 2, "db": 0}