[Solved] Create dictionary using split() operation and list comprehension [closed]


as pointed out by @Delgan, it can be done directly via

d1 = dict(keyval.split(", ") for keyval in a_list)

without the inner nesting 🙂

older approach which were not really correct :-

d = [a.split(',') for a in a_list]
d1 = {key: val for key,val in d}

or

d1 = {key: val for key,val in (a.split(',') for a in a_list)}

3

solved Create dictionary using split() operation and list comprehension [closed]