Skip to content
Advertisement

Check if key-value combinations can be found in Python dict

I am looking for a function found_in_color_dict() which tells me if a certain key-value combination can be found in color_dict. The function returns True or False, respectively.

JavaScript

Based on the example I would expect the following results:

JavaScript

I can only think of complex approaches to solve this problem. But I guess there might be an easy way to solve it, right?

Advertisement

Answer

You can use set.issubset:

Note: dict.itemview acts as a set

JavaScript

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement