[Baypiggies] sorting alphanumeric list
tim at timhatch.com
Tue Jul 19 22:09:02 CEST 2011
> given the following list:
> ['Y6', 'T5']
> how do i modify list a to end up with:
> ['T5', 'Y6']
> of course my actual data consists of nested lists whose elements consist
> lists like list a.
Maybe you could give an example involving A3, B1, and C20. Are you trying
to sort on the numeric part or the letter? Is the letter fixed size?
>>> a=['A3', 'B1', 'C20']
>>> a.sort(key=lambda i: int(i[1:]))
['B1', 'A3', 'C20']
More information about the Baypiggies