-
-
Save parzibyte/c8942277145ac28d921fce04b9817403 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 busqueda_habilidad(self, nombre_a_buscar, nombres_ordenados, pokemones): | |
result = {} | |
izquierda, derecha = 0, len(nombres_ordenados) - 1 | |
while izquierda <= derecha: | |
indiceDelElementoDelMedio = (izquierda + derecha) // 2 | |
elementoDelMedio = nombres_ordenados[indiceDelElementoDelMedio] | |
# Accedemos a 0 porque queremos el primer valor de la tupla, mismo que es el nombre | |
if elementoDelMedio[0] == nombre_a_buscar: | |
# Aquí hemos encontrado al Pokémon. Usamos su índice para acceder al diccionario | |
id = elementoDelMedio[1] | |
return {id: pokemones[id]} | |
if nombre_a_buscar < elementoDelMedio[0]: | |
derecha = indiceDelElementoDelMedio - 1 | |
else: | |
izquierda = indiceDelElementoDelMedio + 1 | |
return {-1: "No encontrado"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment