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 Jaime
def yaml(a):
d={}
[d.update(z) for z in [{y[0]:y[1][1:]} for y in [x.split(':') for x in a.split('\n') if ':' in x]]]
return dict(map(lambda y: (y[0],int(y[1]) if y[1].isdigit() else y[1]), d.items()))
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!")
April 4, 2020