I have two dictionaries, and I want to compare them and see what is different between the two. Where I am getting confused is the dict
. Is there a name for this?
Everything is working fine, I just don't really understand why it works or what it is doing.
x = {"#04": 0, "#05": 0, "#07": 0, "#08": 1, "#09": 0, "#10": 0, "#11": 1, "#12": 1, "#14": 1, "#15": 1, "#17": 0, "#18": 1, "#19": 1, "#20": 1}
y = {"#04": 1, "#05": 0, "#07": 0, "#08": 1, "#09": 0, "#10": 0, "#11": 1, "#12": 1, "#14": 1, "#15": 0, "#17": 1, "#18": 1, "#19": 0, "#20": 1}
dict = {k: x[k] for k in x if y[k] != x[k]}
list = []
for k, v in dict.items()
if v==0:
difference = k + ' became ' + '0'
list.append(difference)
else:
difference = k + ' became ' + '1'
list.append(difference)
print(list)
It should print ['#04 became 0', '#15 became 1', '#17 became 0', '#19 became 1']
but I don't understand how the dict
works to loop through the x and y dictionaries.