On Wed, Jan 13, 2010 at 2:21 PM, Stefan Behnel <[email protected]> wrote:
> 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.

It will work fine if all the list items have the same format which I
would think is the most common case.

Kent
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to