suggestions, comments on an "is_subdict" test

Peter Otten __peter__ at web.de
Fri Apr 22 17:06:03 CEST 2011


Zero Piraeus wrote:

> :
> 
>>> I'd like to ask for comments or advice on a simple code for testing a
>>> "subdict", i.e. check whether all items of a given dictionary are
>>> present in a reference dictionary.
> 
> Anything wrong with this?
> 
> def is_subdict(test_dct, base_dct):
>     return test_dct <= base_dct and all(test_dct[k] == base_dct[k] for
> k in test_dct)

It may raise a KeyError.




More information about the Python-list mailing list