[Tutor] samples on sort method of sequence object.

Stefan Behnel stefan_ml at behnel.de
Wed Jan 13 20:21:58 CET 2010

Hugo Arts, 13.01.2010 15:25:
> Here is my solution for the general case:
> from itertools import groupby
> def alphanum_key(string):
>     t = []
>     for isdigit, group in groupby(string, str.isdigit):
>         group = ''.join(group)
>         t.append(int(group) if isdigit else group)
>     return t

Note that this won't work in Py3, where integers and strings are not 
ordered, i.e. not comparable w.r.t the < and > operators.


More information about the Tutor mailing list