I have been trying to play abit with two list that includes dicts. Basically I have two list that are following:
listA = [{'name': 'ColorR', 'color': 'Red'}, {'name': 'ColorB', 'color': 'Blue'}, {'name': 'ColorP', 'color': 'Purple'}, {'name': 'ColorO', 'color': 'Orange'}, {'name': 'ColorW', 'color': 'White'}]
listB = [{'name': 'ColorR', 'color': 'Red'}, {'name': 'ColorP', 'color': 'Purple'}, {'name': 'ColorO', 'color': 'Orange'}, {'name': 'ColorW', 'color': 'White'}]
What I try to achieve here is that I want to compare listA with listB and print out whatever that is not in listB from listA. In our case we don't have {'name': 'ColorB', 'color': 'Blue'}
in listB meaning in that case the output would be:
{'name': 'ColorB', 'color': 'Blue'}
However I did not found any similar to my problem due to I have "comma" inside a dict. (maybe it is not a correct of dicts??)
I would appreciate every sort of help to solve my issue of printing out the dicts that are not in listB.
It's simple. Use loop to iterate each element in
listA
and if-statement to compare it with all elements inlistB
:Output: