Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'exception': 0.03; 'bug.': 0.07; 'table.': 0.07; 'undefined': 0.07; 'missed': 0.09; 'python': 0.09; 'shame': 0.09; 'cc:addr:python-list': 0.10; 'def': 0.10; '(but': 0.15; '(11': 0.16; 'humour': 0.16; 'int.': 0.16; 'least,': 0.16; 'naming': 0.16; 'wrote:': 0.17; 'comparing': 0.17; "shouldn't": 0.17; 'input': 0.18; 'code.': 0.20; 'sort': 0.21; "i'd": 0.22; '>': 0.23; 'cc:no real name:2**0': 0.24; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'leave': 0.26; 'cc:addr:gmail.com': 0.27; 'coding': 0.27; 'message-id:@mail.gmail.com': 0.27; 'post': 0.28; 'crash': 0.29; 'scheme.': 0.29; 'character': 0.29; 'skip:& 10': 0.29; "i'm": 0.29; 'december': 0.32; 'skip:& 20': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'thanks': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'really': 0.36; "didn't": 0.36; 'enough': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'sure': 0.38; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'first': 0.61; 'thomas': 0.62; 'skip:n 10': 0.63; 'more': 0.63; 'gave': 0.65; 'compact,': 0.84; 'here!': 0.84; '\xa0at': 0.84; 'approach.': 0.91; 'angel': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=x99HplAC+FThghKlACp8FcWWEdCVLZitGViAi0Z5jPU=; b=fJ5mlabzaUP8d7+N6Ve6CDJLMkEgudXj3CQ9SH0RWlvAz5Upvz6Lhbn7NDsgivn9RC fs0VhBQqC+tYFsu4RqIugGZDg32XwPdU2glBEOmU2QHpxnTtj8UDH2pUoRTunX3bcCCv fB8+NZG7h7rDtXg0AMu4c8iY2AFHPul3tUwZx9Of9Exs2OkNHkwu0to6dEDruOP1gykW gx/ri2otKehRS+ww/IEsN99Lgr4WZF0i3luPbyQ1JMf6ir1witIJR52fo4Qz+mj7JZX9 NFFWREwCLvcUj4jPLDO2aCbn/rn94NCdaoKumfqVGg45+JDYsVsCh9tLkv6vGqabTToY I00w== MIME-Version: 1.0 In-Reply-To: <50D9453D.3090907@davea.name> References: <945054f8-9827-4aaf-9c4d-00970404ca18@googlegroups.com> <50D9453D.3090907@davea.name> From: Joshua Landau Date: Thu, 27 Dec 2012 01:13:11 +0000 Subject: Re: Custom alphabetical sort To: d@davea.name Content-Type: multipart/alternative; boundary=047d7b6226768335c904d1cb42bd Cc: python-list , pander.musubi@gmail.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 122 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1356570839 news.xs4all.nl 6913 [2001:888:2000:d::a6]:53816 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35562 --047d7b6226768335c904d1cb42bd Content-Type: text/plain; charset=ISO-8859-1 On 25 December 2012 06:18, Dave Angel wrote: > On 12/24/2012 06:19 PM, Pander Musubi wrote: > > Thanks very much for this efficient code. > > Perhaps you missed Ian Kelly's correction of Thomas Bach's approach: > > d = { k: v for v, k in enumerate(cs) } > > > def collate(x): > return list(map(d.get, x)) > > sorted(data, key=collate) > > I'd use Ian Kelly's approach. Well, he was first to it :P > It's not only more compact, I take offence* here! The only difference was "list(map(d.get, x))" vs "[hashindex[s] for s in string]" (11 chars) and my longer naming scheme. If you really care enough about those to sway your judgement, shame on you! ;) * Not really it shouldn't > give an exception for a character not in the table. That was a choice, not a bug. I didn't want undefined behaviour, so I thought I'd leave it to crash on "bad" input than sort in a way that may be unwanted. Even Ian Kelly gave this as way of coding it. > At least, not for > Python 2.x. I'm not sure about Python 3, since it can give an exception > comparing None to int. Please not that this post was done in humour (but with truth) to delay sleep. No offence to Ian or you intended ;). Happy After-Christmas! --047d7b6226768335c904d1cb42bd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On 25 December 2012 06:18, Dave Angel &l= t;d@davea.name> wrote:
On 12/24/2012 06:19 PM, Pander Musubi wrote:
=A0<= ;snip>
> Thanks very much for this efficient code.

Perhaps you missed Ian Kelly's correction of Thomas Bach's ap= proach:

d =3D { k: v for v, k in enumerate(cs) }


def collate(x):
=A0 =A0 return list(map(d.get, x))

sorted(data, key=3Dcollate)

I'd use Ian Kelly's approach.

Well, he was first to it :P
=A0
It's not only more compact,

I tak= e offence* here! The only difference was "list(map(d.get, x))" vs= "[hashindex[s] for s in string]" (11 chars) and my longer naming= scheme. If you really care enough about those to sway your judgement, sham= e on you! ;)

* Not really

it shouldn't
give an exception for a character not in the table.

That was a choice, not a bug. I didn't want undefined be= haviour, so I thought I'd leave it to crash on "bad" input th= an sort in a way that may be unwanted. Even Ian Kelly gave this as way of c= oding it.
=A0
At least, not for
Python 2.x. =A0I'm not sure about Python 3, since it can give an except= ion
comparing None to int.


Please not that this post was done in humour (but with truth) to delay sle= ep. No=A0offence=A0to Ian or you intended ;).

Happy After-Christmas!
--047d7b6226768335c904d1cb42bd--