Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #87754
| Return-Path | <python-python-list@m.gmane.org> |
|---|---|
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'operator': 0.03; 'imply': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'behave': 0.16; 'deprecated,': 0.16; 'dictionaries': 0.16; 'equal.': 0.16; 'expecting': 0.16; 'finney': 0.16; 'operators.': 0.16; 'pythonic': 0.16; 'reason?': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:versus': 0.16; 'then?': 0.16; 'url:whatsnew': 0.16; 'values?': 0.16; 'do.': 0.18; 'seems': 0.21; 'saying': 0.22; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'comparing': 0.24; 'compare': 0.26; 'header:X-Complaints-To:1': 0.27; 'asked': 0.31; 'went': 0.31; 'comparison': 0.31; 'equality': 0.31; 'operators': 0.31; 'values.': 0.31; 'wright': 0.31; 'writes:': 0.31; 'yes.': 0.31; 'url:python': 0.33; 'there': 0.35; 'really': 0.36; 'false': 0.36; 'doing': 0.36; 'url:org': 0.36; 'should': 0.36; 'example,': 0.37; 'two': 0.37; 'ben': 0.38; 'to:addr:python-list': 0.38; 'expect': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'most': 0.60; 'url:3': 0.61; 'different': 0.65; 'url:0': 0.67; 'between': 0.67; '8bit%:21': 0.69; 'borrow': 0.84; 'received:125': 0.84; 'victor': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Ben Finney <ben+python@benfinney.id.au> |
| Subject | Re: Deep comparison of dicts - cmp() versus ==? |
| Date | Fri, 20 Mar 2015 13:33:50 +1100 |
| References | <d88b9040-b566-48fc-89e9-c6dffcd369bd@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | jigong.madmonks.org |
| X-Public-Key-ID | 0xAC128405 |
| X-Public-Key-Fingerprint | 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 |
| X-Public-Key-URL | http://www.benfinney.id.au/contact/bfinney-pubkey.asc |
| X-Post-From | Ben Finney <bignose+hates-spam@benfinney.id.au> |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
| Cancel-Lock | sha1:PQhuxySmWV82/lMFNekt+MRBHek= |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.19 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.31.1426818822.10327.python-list@python.org> (permalink) |
| Lines | 52 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1426818822 news.xs4all.nl 2912 [2001:888:2000:d::a6]:55098 |
| X-Complaints-To | abuse@xs4all.nl |
| Path | csiph.com!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
| Xref | csiph.com comp.lang.python:87754 |
Show key headers only | View raw
Victor Hooi <victorhooi@gmail.com> writes:
> What is the currently most Pythonic way for doing deep comparisons
> between dicts?
What distinction do you intend by saying “deep comparison”? As
contrasted with what?
> For example, say you have the following two dictionaries
>
> a = {
> 'bob': { 'full_name': 'bob jones', 'age': 4, 'hobbies': ['hockey', 'tennis'], 'parents': { 'mother': 'mary', 'father', 'mike'}},
> 'james': { 'full_name': 'james joyce', 'age': 6, 'hobbies': [],}
> }
>
> b = {
> 'bob': { 'full_name': 'bob jones', 'age': 4, 'hobbies': ['hockey', 'tennis']},
> 'james': { 'full_name': 'james joyce', 'age': 5, 'hobbies': []}
> }
Those two dicts are not equal. How would your intended “deep comparison”
behave for those two values?
> However, this page seems to imply that cmp() is deprecated?
> https://docs.python.org/3/whatsnew/3.0.html#ordering-comparisons
It is, yes.
> Should we just be using the equality operator ("==") instead then? E.g.:
>
> a == b
Yes. That is a comparison that would return False for comparing the
above two values. Would you expect different behaviour?
> What is the reason for this?
I don't really understand. ‘cmp’ is deprecated, and you can compare two
dicts with the built-in operators. That's the reason; are you expecting
some other reason?
> Or is there a better way to do this?
I don't really know what it is you want to do. What behaviour different
from the built-in comparison operators do you want?
--
\ “I went over to the neighbor's and asked to borrow a cup of |
`\ salt. ‘What are you making?’ ‘A salt lick.’” —Steven Wright |
_o__) |
Ben Finney
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Deep comparison of dicts - cmp() versus ==? Victor Hooi <victorhooi@gmail.com> - 2015-03-19 19:00 -0700
Re: Deep comparison of dicts - cmp() versus ==? Ben Finney <ben+python@benfinney.id.au> - 2015-03-20 13:33 +1100
Re: Deep comparison of dicts - cmp() versus ==? Victor Hooi <victorhooi@gmail.com> - 2015-03-19 19:57 -0700
Re: Deep comparison of dicts - cmp() versus ==? Rustom Mody <rustompmody@gmail.com> - 2015-03-19 20:27 -0700
Re: Deep comparison of dicts - cmp() versus ==? Chris Angelico <rosuav@gmail.com> - 2015-03-20 14:34 +1100
Re: Deep comparison of dicts - cmp() versus ==? Rustom Mody <rustompmody@gmail.com> - 2015-03-19 20:47 -0700
Re: Deep comparison of dicts - cmp() versus ==? Chris Angelico <rosuav@gmail.com> - 2015-03-20 15:35 +1100
Re: Deep comparison of dicts - cmp() versus ==? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-03-20 17:35 +1100
Re: Deep comparison of dicts - cmp() versus ==? Roy Smith <roy@panix.com> - 2015-03-20 08:49 -0400
Re: Deep comparison of dicts - cmp() versus ==? Rustom Mody <rustompmody@gmail.com> - 2015-03-20 06:46 -0700
Re: Deep comparison of dicts - cmp() versus ==? Ben Finney <ben+python@benfinney.id.au> - 2015-03-20 16:09 +1100
Re: Deep comparison of dicts - cmp() versus ==? Rustom Mody <rustompmody@gmail.com> - 2015-03-20 06:35 -0700
Re: Deep comparison of dicts - cmp() versus ==? Marko Rauhamaa <marko@pacujo.net> - 2015-03-20 16:10 +0200
OT Intuitionism+Platonism+Mysticism => CS (was Deep comparison of dicts...) Rustom Mody <rustompmody@gmail.com> - 2015-03-20 23:01 -0700
Re: OT Intuitionism+Platonism+Mysticism => CS (was Deep comparison of dicts...) Marko Rauhamaa <marko@pacujo.net> - 2015-03-21 08:28 +0200
Re: OT Intuitionism+Platonism+Mysticism => CS (was Deep comparison of dicts...) Rustom Mody <rustompmody@gmail.com> - 2015-03-31 20:53 -0700
Re: Deep comparison of dicts - cmp() versus ==? Chris Angelico <rosuav@gmail.com> - 2015-03-20 16:27 +1100
csiph-web