Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
str.splitlines, str.split, str.replace and match statement solution in Clear category for YAML. More Types by balintd
def yaml(a: str) -> dict:
objs = {}
for line in a.splitlines():
if line != "":
k, v = line.split(":")
v = v.strip()
try:
v = int(v)
except ValueError:
match v:
case "false":
v = False
case "true":
v = True
case "":
v = None
case "null":
v = None
case _:
v = v.replace('"', '').replace('\\', '"')
else:
continue
objs[k] = v
return objs
Oct. 15, 2024
Comments: