merging Python dictionaries

前端 未结 4 2017
时光说笑
时光说笑 2020-11-27 04:40

I am trying to merge the following python dictionaries as follow:

dict1= {\'paul\':100, \'john\':80, \'ted\':34, \'herve\':10}
dict2 = {\'paul\':\'a\', \'joh         


        
4条回答
  •  难免孤独
    2020-11-27 05:36

    output = {k: [dict1[k], dict2.get(k)] for k in dict1}
    output.update({k: [None, dict2[k]] for k in dict2 if k not in dict1})
    

提交回复
热议问题