Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
YAML. Simple Dict solution in Uncategorized category for YAML. Simple Dict by Elena_Korljukova
def yaml(a):
q = [j for x in a.split('\n') if x for j in x.split(': ')]
return {q[i]:(int(q[i+1]) if q[i+1].isdigit() else q[i+1]) for i in range(0,len(q),2)}
if __name__ == '__main__':
print("Example:")
print(yaml("""name: Alex Fox
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!")
June 26, 2020