Source

Sort this messy list / casier.py

Full commit




class Casier(object):
    """
    Casier sort - O(n)
    """
    def __init__(self, l):
        self.unsorted_list = l

    def sort(self):
        l = self.unsorted_list
        maxi=max(l)
        ll = []
        for i in range(len(str(maxi))):
            ll.append([])
        for j in range(len(str(maxi))):
            for k in range(11):
                ll[j].append([])
        for i in l:
            ll[len(str(i))-1][10].append(i)
        for i in range(len(str(maxi))):
            for j in reversed(range(i+1)):
                for k in ll[i][10]:
                    ll[i][int(str(k)[j])].append(k)
                ll[i][10]=[]
                for m in range(10): ll[i][10].extend(ll[i][m])
                for m in range(10): ll[i][m]=[]
        l=[]
        for i in range(len(str(maxi))):
            l.extend(ll[i][10])