Possible Duplicate:
In Python, how can I naturally sort a list of alphanumeric strings such that alpha characters sort ahead of numeric characters?
How do you sort a string containing numbers and characters in python?
Possible Duplicate:
In Python, how can I naturally sort a list of alphanumeric strings such that alpha characters sort ahead of numeric characters?
How do you sort a string containing numbers and characters in python?
>>> s = '13abc3'
>>> ''.join(sorted(s, key=lambda x: int(x) if x.isdigit() else x))
'133abc'
This doesn't handle any custom sorting if that is what you're after (this goes number, uppercase, lowercase).