def dictionarize(s, d={}, key=None): """ Simple recursive function to convert a yaml literal block string ("|-") to yaml-valid python dictionary Args: s, str: yaml-valid input string d, dict: output dictionary key, str: key in the dictionary at which to add nested values Returns: d, dict: yaml-valid python dictionary """ if isinstance(s, str): s = s.split('\n') for kv in list(s): try: k, v = kv.split(':') except ValueError: if kv in s: s.remove(kv) dictionarize(s, d) if v: if key: d[key][k.strip()] = v.strip() else: d[k] = v.strip() else: key = k.strip() d[k.strip()] = {} if kv in s: s.remove(kv) return d