I'm trying to compare 2 lists of dictionaries.
Please find an example below.
list1 = [
{'code': '1111', 'description': 'Test'},
{'code': '2222', 'description': 'Hello World'},
{'code': '3333', 'description': 'Stack'},
{'code': '4444', 'description': 'Gozilla'},
]
list2 = [
{'code': '3333', 'description': 'Stack'},
{'code': '4444', 'description': 'Megatron'},
{'code': '5555', 'description': 'Winnie the Pooh'}
]
I am trying to :
- If ['code'] from list2 exist in list1, and if ['description'] is different, place it in a new list "updates".
- If ['code'] from list2 does not exist in list1, place it in a new list "new".
At the end the 2 new lists from my example should look like that :
updates = [
{'code': '4444', 'description': 'Megatron'}
]
new = [
{'code': '5555', 'description': 'Winnie the Pooh'}
]
Any ideas how I could achieve that ?