Digital Marketing

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])]

Popular posts from this blog

How to fix Google Apps Script: Script function not found: doGet

Creating sort index in MySQL

How to fix: df shows no file systems processed on Linux