Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #106441
| Path | csiph.com!weretis.net!feeder4.news.weretis.net!storethat.news.telefonica.de!feedme.news.telefonica.de!telefonica.de!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Peter Otten <__peter__@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: Sorting a list |
| Date | Mon, 04 Apr 2016 16:12:13 +0200 |
| Organization | None |
| Lines | 25 |
| Message-ID | <mailman.19.1459779546.32530.python-list@python.org> (permalink) |
| References | <ndrn97$bco$1@dont-email.me> <mailman.408.1459711883.28225.python-list@python.org> <ndrt29$36l$1@dont-email.me> <ndt36r$oi$1@ger.gmane.org> <1459777242.3422585.568322458.4B66944D@webmail.messagingengine.com> <ndtsnu$s0a$1@ger.gmane.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Trace | news.uni-berlin.de ioBy7IvxmGye1MZ8hgkXBgtcsmPrRbx1mxpL1bhR+NwQ== |
| 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.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'operator': 0.03; 'type,': 0.07; 'wrapper': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.13; "'b',": 0.16; "'c',": 0.16; "'d',": 0.16; '__lt__(self,': 0.16; 'key):': 0.16; 'negation': 0.16; 'orderable': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'reversed': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'second': 0.24; 'import': 0.24; 'mon,': 0.24; 'header :User-Agent:1': 0.26; 'subject:list': 0.26; 'header:X-Complaints- To:1': 0.26; 'skip:_ 10': 0.32; 'class': 0.33; 'though.': 0.33; "isn't": 0.35; 'but': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'thought': 0.37; 'why': 0.39; 'does': 0.39; 'well.': 0.40; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'otten': 0.84 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| X-Gmane-NNTP-Posting-Host | p57bd80fb.dip0.t-ipconnect.de |
| User-Agent | KNode/4.13.3 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| 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> |
| X-Mailman-Original-Message-ID | <ndtsnu$s0a$1@ger.gmane.org> |
| X-Mailman-Original-References | <ndrn97$bco$1@dont-email.me> <mailman.408.1459711883.28225.python-list@python.org> <ndrt29$36l$1@dont-email.me> <ndt36r$oi$1@ger.gmane.org> <1459777242.3422585.568322458.4B66944D@webmail.messagingengine.com> |
| Xref | csiph.com comp.lang.python:106441 |
Show key headers only | View raw
Random832 wrote:
> On Mon, Apr 4, 2016, at 02:56, Peter Otten wrote:
>> > That works well. Why is it 'cheating'?
>>
>> On second thought it isn't ;)
>
> It does require a numeric type, though. There are lots of types that are
> orderable but do not have a negation operator that provides a key with
> reversed ordering.
If you are willing to accept the overhead you can use a wrapper class:
>>> import functools
>>> @functools.total_ordering
... class neg:
... def __init__(self, key):
... self.key = key
... def __lt__(self, other):
... return other.key < self.key
...
>>> sorted("abcde", key=neg)
['e', 'd', 'c', 'b', 'a']
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Sorting a list DFS <nospam@dfs.com> - 2016-04-03 14:30 -0400
Re: Sorting a list DFS <nospam@dfs.com> - 2016-04-03 14:34 -0400
Re: Sorting a list Peter Otten <__peter__@web.de> - 2016-04-03 21:31 +0200
Re: Sorting a list DFS <nospam@dfs.com> - 2016-04-03 16:08 -0400
Re: Sorting a list Peter Otten <__peter__@web.de> - 2016-04-04 08:56 +0200
Re: Sorting a list Random832 <random832@fastmail.com> - 2016-04-04 09:40 -0400
Re: Sorting a list Peter Otten <__peter__@web.de> - 2016-04-04 16:12 +0200
csiph-web