Removing duplicate keys from python dictionary but summing the values

前端 未结 8 1999
陌清茗
陌清茗 2021-01-15 05:30

I have a dictionary in python

d = {tags[0]: value, tags[1]: value, tags[2]: value, tags[3]: value, tags[4]: value}

imagine that this dict i

8条回答
  •  伪装坚强ぢ
    2021-01-15 05:47

    This option serves but is done with a list, or best can provide insight

    data = []
            for i, j in query.iteritems():
                data.append(int(j))    
            try:
                data.sort()
            except TypeError:
                del data
            data_array = []
            for x in data:
                if x not in data_array:
                    data_array.append(x)  
            return data_array
    

提交回复
热议问题