Created
September 17, 2018 16:31
-
-
Save marcoshipe/fd051c71ce15380b3760c3a7270de82c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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