sorting - Sort alphanumeric list -
i'm trying sort list numbers found in each element.
revision_type = [('100k revision', '50k revision', '25k revision')]
this i've come far keep getting error:
attributeerror: 'tuple' object has no attribute 'partition' revision_sorted = sorted(revision_type, key=lambda s: (int(s.partition(' ')[0][:-1])))
i want list revision_sorted
be:
[('25k revision', '50k revision', '100k revision')]
been messing hours, appreciated.
i think close. revision_type list has tuple. so, have extract first element , pass sorted function.
revision_type = [('100k revision', '50k revision', '25k revision')] revision_sorted = [tuple(sorted(revision_type[0], key=lambda s: (int(s.partition(' ')[0][:-1]))))] print revision_sorted
output
[('25k revision', '50k revision', '100k revision')]
Comments
Post a Comment