Merging two lists into dictionary while keeping duplicate data in python

后端 未结 8 2131
北海茫月
北海茫月 2021-01-17 09:09

Hi, I want to merge two lists into one dictionary. Suppose I have two lists such as below

list_one = [\'a\', \'a\', \'c\', \'d\']

list_two = [1,2,3,4]

8条回答
  •  梦谈多话
    2021-01-17 09:47

    Dictionary has unique keys. If you need the value of 'a' separately store the zipped data in a list or you can use list in values part of the dict and store the values as: {'a': [1,2],'c': [3], 'd': [4]}

提交回复
热议问题