On Nov 3, 1:51 pm, [EMAIL PROTECTED] wrote:

> Arnaud Delobelle:
>
> > Here's another idea, probably more practical:
> > >>> sorted(s, key=lambda x: tuple(256-ord(l) for l in x), reverse=True)
>
> Nice.
> A variant that probably works with unicode strings too:
>
> print sorted(s, key=lambda x: [-ord(l) for l in x], reverse=True)
>
> Bye,
> bearophile

Awesome! I tested it on a sample list of ~61K words [1] and it's
almost 40% faster, from ~1.05s dropped to ~0.62s. That's still >15
times slower than the default sorting (0.04s) but I guess there's not
much more room for improvement.

George

[1] 
http://www.cs.pitt.edu/~kirk/cs1501/Pruhs/Spring2006/assignments/boggle/5desk.txt
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to