简单地在字典python中添加值

时间:2016-03-16 17:42:39

标签: python

我想将字典附加为字典的第二个值第二个值

ret = {}
third_value_list =[0,1]
for i in third_value_list:
    #print i
    num_list = [1,2]
    val_list = [0,1]
    dict1 = dict(zip(num_list,val_list))
    print dict1
    num_list2= [1,2]
    val_list2 = [0,6]
    dict2 =dict(zip(num_list2,val_list2))
    print dict2
if set(dict2.items()) - set(dict1.items()):
    print 'true'
    a = set(dict1.items()) - set(dict2.items())
    ret.update (a)
    print ret
    print 'this is before'
    for key in ret:
       ret[key] = [ret[key]]
       ret[key].append(i)
       print ret

当前输出:

{1:0,2:1}

{1:0,2:6}

{1:0,2:1}

{1:0,2:6}

{2:1}

这是在#below是最终输出

之前

{2:[1,1]}

欲望输出:{2:[1,0],2:[1,1]}

1 个答案:

答案 0 :(得分:0)

我问题的答案是ret [i] = a