

#Python compare dictionaries keys and values code#
Your own code doesn't work because python dictionaries are not lists you don't. keys() returns the keys through a dictkeys object.values() returns the values through a dictvalues ems() returns. Set comprehensions were introduced in Python 2.7 in earlier versions use: chr set (v 'chr' for v in ervalues ()) In Python 3, you'd need to replace. I would group the sublists in a dict by the first element which is the letter then iterate over your original dict and check if each key is in the grouping dict and do your comparison. You can check that dictionary2.keys() is a subset of dictionary1.keys() with the < operator: print(dictionary2.keys() < dictionary1. This uses a set comprehension to generate your set in one line of code.
