16 lines
419 B
Python
16 lines
419 B
Python
|
G
|
def parse_kv(text):
|
||
|
|
result = {}
|
||
|
|
for line in text.splitlines():
|
||
|
|
line = line.strip()
|
||
|
|
if not line:
|
||
|
|
continue
|
||
|
|
key, value = line.split('=', 1)
|
||
|
|
if value.isdigit():
|
||
|
|
value = int(value)
|
||
|
|
result[key] = value
|
||
|
|
return result
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
assert parse_kv('a=1\nb=hello\n\nc=42') == {'a': 1, 'b': 'hello', 'c': 42}
|
||
|
|
print("Test passed!")
|