Parse a key=value Config File

Medium ⏱ 12 min 54% acceptance ★★★★☆ 4.3
Write load_config(path) that parses lines of key=value into a dict. Skip blank lines and lines starting with #. Values keep everything after the first = (so url=http://x?a=1 works). Strip whitespace around both parts.

Examples

Example 1
Input
load_config('app.cfg')  # 'host = local\n# note\nurl=http://x?a=1\n'
Output
{'host': 'local', 'url': 'http://x?a=1'}
Explanation

Comment skipped; the second = survives inside the value.

Constraints

  • Split on the first = only.
  • Skip comments (#) and blanks.

Topics

File Handlingparsing

Companies

ServiceNowAtlassianWipro

Hints

Hint 1

line.split('=', 1) limits the split.

Hint 2

partition() is an equally clean option.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.