Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
That was needy... solution in Clear category for Determine the Order by new_hoschi
def checkio(data):
## this is gonna be our solution, letters will be only be appended,
## not inserted
alphabet = ''
## presort the letters by usual latin alphabet ordering
## to assure correct order of uncategorizable letters
letter_list = sorted(set().union(*data))
## looks like that:
print(letter_list)
''' For every letter in that list, try to figure out if it is the next to
come in the alphabet, if so delete it from the data and restart at the
beginning '''
while letter_list:
## check every single character (letter) to be the next for alphabet
for char in letter_list:
## if char is the first letter of one (or more) word(s) and in no
## other position in any word, then it has to be the next
## (luckily we already sorted our list by latin alphabet, which
## gives us the correct ordering here even
## for the undetermined case)
if all(char not in word or char == word[0] for word in data):
## append the letter to the alphabet and eliminate all
## appearances in letter_list and in data
alphabet += char
letter_list=[j for j in letter_list if j!=char]
for i in range(len(data)):
data[i] = data[i].replace(char, '')
## if you found the a letter for alphabet, break and restart
## your search at the start of the remaining letter_list
break
return alphabet
April 14, 2020
Comments: