Converting List to dicts


Can anyone tell me how to convent a list to list of dicts ?


convert? Can you give an example of how you would this to look like?


l = ['a' , 'b' , 'c' ,'d']
required output
dl = [{'a' : 'b', 'c' : 'd'}]


that is surprisingly tricky, took me a second. General idea:

l = ['a' , 'b' , 'c' ,'d']
counter = 0;
list_length = len(l)
while counter < list_length:
     d[l[counter]] = l[counter+1]
     counter += 2
print dl

not the greatest code in the world, but its a start


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.