<div dir="ltr">On 25 December 2012 06:18, Dave Angel <span dir="ltr"><<a href="mailto:d@davea.name" target="_blank">d@davea.name</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

On 12/24/2012 06:19 PM, Pander Musubi wrote: </blockquote><div style> <snip></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div class="im">
> Thanks very much for this efficient code.<br>
<br>
</div>Perhaps you missed Ian Kelly's correction of Thomas Bach's approach:<br>
<div class="im"><br>
d = { k: v for v, k in enumerate(cs) }<br>
<br>
<br>
</div><div class="im">def collate(x):<br>
    return list(map(d.get, x))<br>
<br>
sorted(data, key=collate)<br>
<br>
</div>I'd use Ian Kelly's approach.</blockquote><div><br></div><div style>Well, he was first to it :P</div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

It's not only more compact,</blockquote><div><br></div><div style>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! ;)</div>

<div style><br></div><div style>* Not really</div><div style><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

it shouldn't<br>
give an exception for a character not in the table.</blockquote><div><br></div><div style>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.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">At least, not for<br>
Python 2.x.  I'm not sure about Python 3, since it can give an exception<br>
comparing None to int.</blockquote><div><br></div><div><br></div><div style>Please not that this post was done in humour (but with truth) to delay sleep. No offence to Ian or you intended ;).</div><div style><br></div><div style>

Happy After-Christmas!</div></div></div></div>