Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for YAML. Simple Dict by gleb10101010101
def yaml(a: str) -> dict:
data = [i for i in a.split('\n') if i] # Преобразование в список, ликвидация пустых строк
data = [tuple(i.split(': ')) for i in data] # Деление по двоеточию с пробелом
return dict([(i[0], int(i[1])) if all([j.isdigit() for j in i[1]]) else i for i in data]) # Словаризация с учетом int
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!")
Oct. 19, 2023