Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #52393
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <jsf80238@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'elif': 0.05; 'steve': 0.09; 'attributes': 0.09; 'snippet': 0.09; 'cc:addr :python-list': 0.11; 'def': 0.12; '__lt__(self,': 0.16; 'attributes.': 0.16; 'extensible': 0.16; 'subject:Elegant': 0.16; 'subject:compare': 0.16; 'cc:addr:python.org': 0.22; 'question': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'adequate': 0.31; 'them?': 0.31; 'class': 0.32; 'skip:_ 10': 0.34; 'received:google.com': 0.35; 'should': 0.36; 'too': 0.37; 'thank': 0.38; 'combining': 0.68; 'said:': 0.68; 'short,': 0.84; 'to:none': 0.92 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=gybZkk3R31+SLcGG/ryK6B1b5JUHpLCdWNwh5/QBKTI=; b=q5MlrLYacDmStNcMVLA80T+uLmtJEzxdWiWPlw+ApLiGyebUA1TG7Ypyn9h+SkO3qD muV+J6SybKYYF1aMOnamf/zwbACd9CSRmIWJUHOruoxFsdtnAmTR+vGnBYTtQe1uBMnC CbEQIxHvxYiLMq/QfKqNLeOG2ac+lr/GR/8B+72/jizU+rUlOONIlMwYutUGzwhIaXRV Qqn75d6LioJEdboEVkMeALwz3el2kaGodfZbtz193sLdNRgAZW9RXVf2bTPZj5zvfFSf IC9VjdrVw95pf2fEVgwqnd9nsBPNBsKP87Lx6hQ4oASDKAuci8WKPB0kgua/TzBQIvea hQLg== |
| MIME-Version | 1.0 |
| X-Received | by 10.205.10.132 with SMTP id pa4mr3106466bkb.15.1376234233663; Sun, 11 Aug 2013 08:17:13 -0700 (PDT) |
| In-Reply-To | <52074ab3$0$30000$c3e8da3$5496439d@news.astraweb.com> |
| References | <mailman.460.1376192467.1251.python-list@python.org> <52074ab3$0$30000$c3e8da3$5496439d@news.astraweb.com> |
| Date | Sun, 11 Aug 2013 09:17:13 -0600 |
| Subject | Re: Elegant compare |
| From | Jason Friedman <jsf80238@gmail.com> |
| Cc | python-list <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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.486.1376236134.1251.python-list@python.org> (permalink) |
| Lines | 23 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1376236134 news.xs4all.nl 15875 [2001:888:2000:d::a6]:33416 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:52393 |
Show key headers only | View raw
> This is a hard question to answer, because your code snippet isn't
> clearly extensible to the case where you have ten attributes. What's the
> rule for combining them? If instance A has five attributes less than
> those of instance B, and five attributes greater than those of instance
> B, which wins?
Yes, my code snippet was too short, I should have said:
class my_class:
def __init__(self, attr1, attr2, attr3):
self.attr1 = attr1 #string
self.attr2 = attr2 #string
self.attr3 = attr3 #string
def __lt__(self, other):
if self.attr1 < other.attr1:
return True
elif self.attr2 < other.attr2:
return True
else:
return self.attr3 < other.attr3
Chris's answer is actually perfectly adequate for my needs.
Thank you Steve and Chris.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Elegant compare Jason Friedman <jsf80238@gmail.com> - 2013-08-10 21:41 -0600
Re: Elegant compare Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-08-11 08:26 +0000
Re: Elegant compare Jason Friedman <jsf80238@gmail.com> - 2013-08-11 09:17 -0600
csiph-web