I know variations on this question already exist, but I cannot find one that matches exactly what I am trying to achieve. I have the following code, which included a solution I have taken from a solution to a similar question:
b = {"1":0,"2":0,"3":0,"4":0,"5":0}
c = {"1":1,"4":4,"5":5}
d = [k for k in b if c.get(k, object()) > b[k]]
print d
What I want is to compare all the key and value pairs of the dictionary b
with those of c
. If a key and value pair is missing from c
then the key/pair value of b
is retained in the dictionary d
, else the values in c
are retained in d
.
In the example above d
should look like this:
d = {"1":1,"2":0,"3":0,"4":4,"5":5}
Can anyone tell me the correct syntax I need for the line d =
, please?
Thanks