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.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to