How to convert a list of dictionaries to list of tuples in Python

1 Answer

0 votes
lst = [{'python':[1, 2], 'c++':[3, 4, 5]}, 
       {'c':[6], 'php':[7, 8, 9 , 0], 'java':[13, 14]}] 
  
lst_dic = [(key,) + tuple(val) for dic in lst for key, val in dic.items()] 
  
print (lst_dic) 
 



'''
run:
 
[('python', 1, 2), ('c++', 3, 4, 5), ('c', 6), ('php', 7, 8, 9, 0), ('java', 13, 14)]

'''

 



answered Feb 13, 2020 by avibootz
...