Q:

Compare two dictionaries for matches

Not sure why this for loop only prints the values of the dictionary. I'd like to do a comparison between two dictionaries and print the matching keys in both. The matching should be done by key. The keys in this case are the CAS Numbers e.g. 71751412, Abamectin
# create the dictionaries
with open(r'C:\CAS-S.csv') as f:
d = dict(filter(None, csv.reader(f)))
print(d)

with open(r'C:\CAS-B.csv') as f:
g = dict(filter(None, csv.reader(f)))
print(g)

#match keys
for key in d:
  if key in g:
     print (d[key])

A:

The simplest solution:
# match keys
for key in d:
  if key in g:
     print ('{}: {}'.format(key, d[key]))

