Python json数组更新

dict1= {"f1": ["192.168.1.10"], "f2": ["192.168.1.10"]}
dict1_updated= {"f1": ["192.168.1.10"], "f2": ["192.168.1.20"]}

(I'm working on python socket dict1 is updating every minute)

预期的File.json:

{"f1": ["192.168.1.10"], "f2": ["192.168.1.10","192.168.1.20"]}

我的密码

with open("File.json", "w") as file:
    list1=list(set([value for value in dict1.values()]))
    d = dict((key,list1) for key, value in dict1.items())
    json.dump(d, file)
评论