jeudi 16 juin 2016

Get non-matching data when comparing python dicts and store them


I have 2 python dicts... I'm currently checking if they match. But how can I get the non-matched keys and values from items and store them?

data1 = {'first_name': 'John', 'last_name': 'Doe', 'username': 'johndoe'} 
data2 = {'first_name': 'John', 'last_name': 'Doe', 'username': 'johohoho'}

for (key, value) in set(data1.items()) & set(data2.items()):
        print(key, value) 
# this returns only matching data. how can i grab the non matched?

Thank you for your help in advance!


Aucun commentaire:

Enregistrer un commentaire