Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for YAML. Simple Dict by guchshenskaya
def yaml(a: str) -> dict:
data = [i.split(': ') for i in a.split('\n')]
answer = {}
for i in data:
if i[0] != '':
answer[i[0]] = int(i[1]) if i[0] != '' and i[1].isdigit() else i[1]
return answer
print("Example:")
print(
yaml(
"""name: Alex
age: 12"""
)
)
# These "asserts" are used for self-checking
assert yaml("name: Alex\nage: 12") == {"name": "Alex", "age": 12}
assert yaml("name: Alex Fox\nage: 12\n\nclass: 12b") == {
"age": 12,
"name": "Alex Fox",
"class": "12b",
}
print("The mission is done! Click 'Check Solution' to earn rewards!")
March 28, 2023