Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
ddddddd solution in Clear category for YAML. Simple Dict by viktor.chyrkin
def yaml(a):
b = dict()
a = sorted(a.split('\n'))
if '' in a:
a.remove('')
for i in a:
i = i.split(':')
i[-1] = i[-1].strip(' ')
if i[-1].isdigit():
i[-1] = int(i[1])
b[i[0]] = i[-1]
return b
if __name__ == '__main__':
print("Example:")
print(yaml("""name: Alex
age: 12"""))
# These "asserts" are used for self-checking and not for an auto-testing
assert yaml("""name: Alex
age: 12""") == {'age': 12, 'name': 'Alex'}
assert yaml("""name: Alex Fox
age: 12
class: 12b""") == {'age': 12,
'class': '12b',
'name': 'Alex Fox'}
print("Coding complete? Click 'Check' to earn cool rewards!")
Oct. 20, 2021