Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #3877

Re: suggestions, comments on an "is_subdict" test

From Wolfgang Rohdewald <wolfgang@rohdewald.de>
Subject Re: suggestions, comments on an "is_subdict" test
Date 2011-04-22 16:43 +0200
References <BANLkTinazu41uVqxmkfTns0ZOHScZ1a3nQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.752.1303483438.9059.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: suggestions, comments on an "is_subdict" test Wolfgang Rohdewald <wolfgang@rohdewald.de> - 2011-04-22 16:43 +0200

csiph-web