Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #3884
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <z@etiol.net> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'received:209.85.212.46': 0.03; 'received:mail-vw0-f46.google.com': 0.03; 'subject:" ': 0.03; 'subject:test': 0.05; 'seemed': 0.07; '>>>>': 0.09; 'dict': 0.09; 'referenced': 0.09; 'that).': 0.09; 'def': 0.13; ';-)': 0.14; 'wrote:': 0.14; 'equality.': 0.16; 'keyerror:': 0.16; 'remembered': 0.16; 'subject:was': 0.16; 'traceback': 0.16; '(most': 0.16; 'performing': 0.22; 'subject:]': 0.22; 'convert': 0.22; '(and': 0.22; 'last):': 0.23; 'wonder': 0.24; 'worked': 0.24; 'received:209.85.212': 0.25; 'message-id:@mail.gmail.com': 0.28; 'testing': 0.28; 'beyond': 0.28; 'minimal': 0.29; 'comparison': 0.31; 'subject: [': 0.31; 'turns': 0.31; 'to:addr :python-list': 0.32; '...': 0.32; 'url:docs': 0.33; 'actually': 0.34; 'expensive': 0.35; '"",': 0.35; 'test.': 0.35; 'think': 0.36; 'received:209.85': 0.37; 'url:python': 0.37; 'received:google.com': 0.38; 'but': 0.38; 'url:org': 0.38; 'set': 0.39; 'to:addr:python.org': 0.39; 'received:209': 0.39; 'sets': 0.40; 'would': 0.40; "it's": 0.40; 'header:Received:5': 0.40; '2011': 0.62; 'making': 0.62; 'confirm': 0.71; 'link?': 0.84 |
| MIME-Version | 1.0 |
| Sender | z@etiol.net |
| X-Originating-IP | [200.107.244.177] |
| Date | Fri, 22 Apr 2011 14:34:31 -0400 |
| X-Google-Sender-Auth | AvJXVhqIKtaQmVOKmBKISeZ3ddw |
| Subject | dict comparison [was: suggestions, comments on an "is_subdict" test] |
| From | Zero Piraeus <schesis@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.759.1303497274.9059.python-list@python.org> (permalink) |
| Lines | 32 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1303497274 news.xs4all.nl 81479 [::ffff:82.94.164.166]:51408 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:3884 |
Show key headers only | View raw
:
On 22 April 2011 13:30, Peter Otten <__peter__@web.de> wrote:
>>>> 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)
> ...
>>>> is_subdict({1:0}, {2:0})
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "<stdin>", line 3, in is_subdict
> File "<stdin>", line 3, in <genexpr>
> KeyError: 1
>
> I think you have to convert to sets before performing the <= comparison to
> get a proper subset test.
Huh. I thought I remembered that dict comparison worked like set
comparison (and my admittedly minimal testing seemed to confirm that).
Turns out it's actually "consistent, but not otherwise defined" beyond
equality.
http://docs.python.org/reference/expressions.html#id15
I maintain that the behaviour I expected makes more sense ;-) I wonder
whether making it work the way I want it to (dammit) would have been
as prohibitively expensive as the lexicographical comparison mentioned
in the footnote referenced in the above link?
-[]z.
Back to comp.lang.python | Previous | Next | Find similar
dict comparison [was: suggestions, comments on an "is_subdict" test] Zero Piraeus <schesis@gmail.com> - 2011-04-22 14:34 -0400
csiph-web