Merging dictionary value lists in python

后端 未结 6 893
无人及你
无人及你 2020-11-29 10:27

I\'m trying to merge three dictionaries, which all have the same keys, and either lists of values, or single values.

one={\'a\': [1, 2], \'c\': [5, 6], \'b\'         


        
6条回答
  •  失恋的感觉
    2020-11-29 10:50

    See this help or not:

    >>> dic={}
    >>> k=[]
    >>> for i in 'abc':
        k=one[i]+two[i]
        k.append(three[i])
        dic[i]=k
    
    
    >>> dic
    {'c': [5, 6, 5.6, 7.6, 3.4], 'a': [1, 2, 2.4, 3.4, 1.2], 'b': [3, 4, 3.5, 4.5, 2.3]}
    

提交回复
热议问题