How to sort long string as integer
'''
Integers don't sort correctly when viewed as strings because, for example, '8' as a string is less than '18' due to lexicographic ordering. But integers of the same size do sort correctly as strings, so you can sort first by length and then sort by lexicographic sorting.
'''
def bigSorting(unsorted):
return [s[1] for s in sorted([[len(s),s] for s in unsorted])]
Comments
Post a Comment