Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #3880
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: suggestions, comments on an "is_subdict" test |
| Date | 2011-04-22 17:06 +0200 |
| Organization | None |
| References | <BANLkTinazu41uVqxmkfTns0ZOHScZ1a3nQ@mail.gmail.com> <4DB190DC.8050307@mrabarnett.plus.com> <BANLkTikk8VvoTmBG7YPD1A54v_3=SHz-vQ@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.753.1303484755.9059.python-list@python.org> (permalink) |
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.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: suggestions, comments on an "is_subdict" test Peter Otten <__peter__@web.de> - 2011-04-22 17:06 +0200
csiph-web