Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #35562
| References | <roy-BEEA73.11183724122012@news.panix.com> <mailman.1262.1356372812.29569.python-list@python.org> <945054f8-9827-4aaf-9c4d-00970404ca18@googlegroups.com> <50D9453D.3090907@davea.name> |
|---|---|
| From | Joshua Landau <joshua.landau.ws@gmail.com> |
| Date | 2012-12-27 01:13 +0000 |
| Subject | Re: Custom alphabetical sort |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1313.1356570839.29569.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
On 25 December 2012 06:18, Dave Angel <d@davea.name> wrote:
> On 12/24/2012 06:19 PM, Pander Musubi wrote:
<snip>
> > 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!
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Custom alphabetical sort Roy Smith <roy@panix.com> - 2012-12-24 11:18 -0500
Re: Custom alphabetical sort Pander Musubi <pander.musubi@gmail.com> - 2012-12-24 08:40 -0800
Re: Custom alphabetical sort Roy Smith <roy@panix.com> - 2012-12-24 12:40 -0500
Re: Custom alphabetical sort Pander Musubi <pander.musubi@gmail.com> - 2012-12-24 09:53 -0800
Re: Custom alphabetical sort Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-12-24 18:07 +0000
Re: Custom alphabetical sort Joshua Landau <joshua.landau.ws@gmail.com> - 2012-12-24 18:12 +0000
Re: Custom alphabetical sort Pander Musubi <pander.musubi@gmail.com> - 2012-12-24 15:19 -0800
Re: Custom alphabetical sort Dave Angel <d@davea.name> - 2012-12-25 01:18 -0500
Re: Custom alphabetical sort Joshua Landau <joshua.landau.ws@gmail.com> - 2012-12-27 01:13 +0000
Re: Custom alphabetical sort Pander Musubi <pander.musubi@gmail.com> - 2012-12-24 15:19 -0800
Re: Custom alphabetical sort Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-24 22:57 +0000
csiph-web