suggestions, comments on an "is_subdict" test

Wolfgang Rohdewald wolfgang at rohdewald.de
Fri Apr 22 16:43:54 CEST 2011


On Freitag 22 April 2011, Vlastimil Brom wrote:
> check whether all items of a given dictionary are
> present in a reference dictionary

I would not call this is_subdict. That name does not
clearly express that all keys need to have the same
value.

set(subdict.items()) <= set(reference.items())

should be equivalent to your code

if you only want to check for presence of all
keys in the reference dict:

set(subdict.keys()) <= set(reference.keys())

-- 
Wolfgang



More information about the Python-list mailing list