Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Custom alphabetical sort

Reply
Thread Tools

Re: Custom alphabetical sort

 
 
Joshua Landau
Guest
Posts: n/a
 
      12-27-2012
On 25 December 2012 06:18, Dave Angel <(E-Mail Removed)> 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


> 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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom alphabetical sort Pander Musubi Python 8 12-28-2012 10:27 AM
Using Readers for SQL queries in a loop, want to sort results in alphabetical VB.net itfetish@gmail.com ASP .Net 7 04-23-2007 07:35 AM
ListItemCollection Sort Alphabetical =?Utf-8?B?YmVub2l0?= ASP .Net 4 11-03-2005 04:56 PM
Does WordPad have an alphabetical sort function? tomt Computer Support 5 08-16-2004 04:10 AM
Ado sort error-Ado Sort -Relate, Compute By, or Sort operations cannot be done on column(s) whose key length is unknown or exceeds 10 KB. Navin ASP General 1 09-09-2003 07:16 AM



Advertisments