Skip to content

Instantly share code, notes, and snippets.

@marcoshipe
Created September 17, 2018 16:31
Show Gist options
  • Save marcoshipe/fd051c71ce15380b3760c3a7270de82c to your computer and use it in GitHub Desktop.
Save marcoshipe/fd051c71ce15380b3760c3a7270de82c to your computer and use it in GitHub Desktop.
def ordenar_extraterrestre(desordenadas, orden_alfabeto):
def sort_function(word):
key = 0
for i, letter in enumerate(word):
key += orden_alfabeto.index(letter) / (100 ** (i + 1))
return key
# ordenada = ['revestir', 'miel', 'extraterrestre', 'auto', 'automovil', 'al']
try:
return sorted(desordenadas, key=sort_function)
except ValueError:
print('Error: Por lo menos una de las palabras tiene letras que no esta en el alfabeto '
'dado')
if __name__ == '__main__':
lista = ['miel', 'extraterrestre', 'al', 'automovil', 'auto', 'revestir']
alfabeto = 'zyxwvutsrqponmlkjihgfedcba'
print(ordenar_extraterrestre(lista, alfabeto))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment