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])]
https://gist.github.com/i88ca/c1ef547a612bd3cb6fafcb9d1a3d8427

Comments

Popular posts from this blog

Check MySQL query history from command line

Installing chocolatey on Windows