I wrote something like this to convert comma separated list to a dict.
def list_to_dict( rlist ) :
rdict = {}
i = len (rlist)
while i:
i = i - 1
try :
rdict[rlist[i].split(":")[0].strip()] = rlist[i].split(":")[1].strip()
except :
print rlist[i] + ' Not a key value pair'
continue
return rdict
Isn't there a way to
for i, row = enumerate rlist
rdict = tuple ( row )
or something?
{item.split(":") for item in rlist if ":" in item}. If that doesn't work maybe puttuple(item.split(":")). If not this is a lazy slow way{item.split(":")[0]: item.split(":")[1] for item in rlist}Also since this is converting a string to a dictionary look intoast.literalevaland json. - justengel