I'm tasked with generating a few unsorted keys that will then be sorted alphabetically for example
["dba321db32d1", "abc123ab12a1". "abd456ab45a4"] will then be output as ["abc123ab12a1", "abd456ab45a4", "dba321db32d1"]. I understand the concept of bucket sort with numbers, but for the life of me I can't find anything on how to use it with strings I only get results for programs like Java and C or to use radix sort. This is what I ahve so far but can't figure out how to get it to sort.
def binsort(a):
bins = []
for l in range (a, -1,-1,-1):
binsTwo = [[] for _ in range(10)]
for bin in bins:
for e in bin:
binsTwo[e[l]].append(e)
bins = binsTwo
return [e for bin in bins for e in bin]
a = []
print(a.append(gen_key))
I even tried this but still can't get it to sort
def binsort(a):
bins = []
for l in range (a, -1,-1,-1):
binsTwo = ''.join(choice(a) for _ in range(l))
for bin in bins:
for e in bin:
binsTwo[e[l]].append(e)
bins = binsTwo
return [e for bin in bins for e in bin]
a = []
print(a.append(gen_key))
gen_key is part of the code that I am using to generate the strings. The reason I added the gen_key part to this defintion is because I was hoping that it would output the strings sorted.