conversion of python list to dictionary
we a python list:
lst = ['aus:eng,sl','usa:eu,amc']
convert python list to dictionary=
dict={'aus':['eng','sl'],'usa':['eu','amc']}
dict
is the final dictionary that we want
Conversion of python list to dictionary
CodePudding user response:
d_dict = dict()
for i in lst:
i = i.partition(':')
d_dict.update({i[0]:i[2].split(',')})
CodePudding user response:
{locale:countries.split(",") for locale, countries in map(lambda x: x.split(":"), lst)}
{'aus': ['eng', 'sl'], 'usa': ['eu', 'amc']}