Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Dictionary "strategy" for replacing values solution in Clear category for YAML. More Types by swagg010164
def to_value(value):
strategy = {lambda x: x.lower() == "true": True,
lambda x: x.lower() == "false": False,
lambda x: not x or x == 'null': None,
lambda x: x.startswith('"') and x.endswith('"'): value[1:-1],
lambda x: 1: value}
try:
return int(value)
except ValueError:
for func in strategy:
if func(value):
return strategy[func]
def yaml(a):
s = [[i.strip() for i in k.split(':')] for k in a.split('\n') if k != '']
return {a.strip(): to_value(bytes(b, "utf-8").decode('unicode_escape')
) for a, b in s}
Nov. 7, 2019
Comments: