i have a python string in the format:
str = \"name: srek age :24 description: blah blah\"
is there any way to convert it to dictionary th
without re:
r = "name: srek age :24 description: blah blah cat: dog stack:overflow"
lis=r.split(':')
dic={}
try :
for i,x in enumerate(reversed(lis)):
i+=1
slast=lis[-(i+1)]
slast=slast.split()
dic[slast[-1]]=x
lis[-(i+1)]=" ".join(slast[:-1])
except IndexError:pass
print(dic)
{'age': '24', 'description': 'blah blah', 'stack': 'overflow', 'name': 'srek', 'cat': 'dog'}