suggestions, comments on an "is_subdict" test

MRAB python at mrabarnett.plus.com
Fri Apr 22 22:57:56 CEST 2011


On 22/04/2011 21:31, Vlastimil Brom wrote:
> Thanks everyone for your opinions and suggestions!
> I especially like the all(...) approaches of MRAB and Peter Otten,
> however, the set conversion like
>>>> set(test_dct.items())<= set(base_dct.items())
> True
> looks elegant too.

That works only if the values in the dicts are hashable.

> In both approaches I can get rid of the negated comparison and the
> additional "parsing cost" (for me reading it) is not that high.
>
> As for the name,  I tried to make explicit (for this post), that both
> the keys and their values are important in this test, but it doesn't
> matter that much if is_subdict doesn't communicate this well
> (probably?), as the "audience" of this code is not going to be anyone
> but me.
>



More information about the Python-list mailing list