[Tutor] How to numerically sort strings that start with numbers?

Joel Goldstick joel.goldstick at gmail.com
Tue Sep 14 14:41:26 CEST 2010

> > ['3zxc','21 trewuuioi','134445']
> > > rather than ['134445', '21 trewuuioi', '3zxc']?
> > >
> > > Any help would be greatly appreciated
> > > Pete
> There seem to be two different ways of understand the OP sort order.

The way I took it, 3zxc comes first because the number is 3 which is smaller
than 21 which is smaller than 134445.

It happened to be a coincidence that the list reversed was in that same

So, if I am right about the definition of how to sort, the method I would
use is to strip each string of anything beyond its leading digits, save that
as a key, use the string as the value.  Then sort by key

Joel Goldstick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100914/4a932579/attachment.html>

More information about the Tutor mailing list