Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106693
| From | Ian Kelly <ian.g.kelly@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: how to convert code that uses cmp to python3 |
| Date | 2016-04-08 11:05 -0600 |
| Message-ID | <mailman.93.1460135185.2253.python-list@python.org> (permalink) |
| References | (3 earlier) <570778ad$0$1587$c3e8da3$5496439d@news.astraweb.com> <CALwzidn7p8z7AE-HjZRuaZiFPQ1Je793_OHA5H7VYc8DVCu74A@mail.gmail.com> <mailman.85.1460125085.2253.python-list@python.org> <87d1q0giwd.fsf@elektro.pacujo.net> <CALwzid=Bz6Xsz_G3NGJSYNuSYRyDB9JiM7KXAshg-LPcwGckvA@mail.gmail.com> |
On Fri, Apr 8, 2016 at 10:33 AM, Marko Rauhamaa <marko@pacujo.net> wrote: > Ian Kelly <ian.g.kelly@gmail.com>: > >> That's fine for those operations and probably insert, but how do you >> search an AVL tree for a specific key without also using __eq__? > > Not needed: > > ======================================================================== > if key < node.key: > look_right() > elif node.key < key: > look_left() > else: > found_it() > ======================================================================== That makes me a little nervous since it assumes that the keys are totally ordered and could return an incorrect node if they aren't. Granted, the keys *should* be totally ordered if the data structure is being used properly, but an explicit equality check ensures that the worst that could happen is the node simply isn't found despite being present. More to the contextual point, this is still doing two comparisons, even if both of them are less than, so it doesn't really solve the OP's issue.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: how to convert code that uses cmp to python3 Marko Rauhamaa <marko@pacujo.net> - 2016-04-08 11:34 +0300
Re: how to convert code that uses cmp to python3 Steven D'Aprano <steve@pearwood.info> - 2016-04-08 19:23 +1000
Re: how to convert code that uses cmp to python3 Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-08 08:17 -0600
Re: how to convert code that uses cmp to python3 Marko Rauhamaa <marko@pacujo.net> - 2016-04-08 19:33 +0300
Re: how to convert code that uses cmp to python3 Ian Kelly <ian.g.kelly@gmail.com> - 2016-04-08 11:05 -0600
Re: how to convert code that uses cmp to python3 Marko Rauhamaa <marko@pacujo.net> - 2016-04-08 20:14 +0300
csiph-web