-2

Is there any pythonic way to find out this?

dic1 = {'a': 1, 'b': 2, 'points': 100}
dic2 = {'a': 10, 'b': 20, 'points': 100}

---> Ture  # because points in dic1 and dic2 are equal

and also

dic1 = {'a': 1, 'b': 2, 'points': 200}
dic2 = {'a': 10, 'b': 20, 'points': 100}

---> False # because points in dic1 and dic2 are not equal
Amin Rzn
  • 1
  • 1

1 Answers1

0

You can find a way with this post : Comparing two dictionaries and checking how many (key, value) pairs are equal

you'll have to check the length of :

shared_items = {k: dic1[k] for k in dic1 if k in dic2 and dic1[k] == dic2[k]}
print len(shared_items)

Change it a little to avoid error if there is not the same keys in both dicts

Apo
  • 338
  • 1
  • 9