mirror of
https://github.com/LazoCoder/Pokemon-Terminal
synced 2025-02-17 13:28:32 +00:00
31 lines
943 B
Python
31 lines
943 B
Python
# The logic for loading the Pokemon names and numbers from Data/pokemon.txt.
|
|
|
|
|
|
# Load all the Pokemon and their corresponding numbers into a list.
|
|
def load_names():
|
|
names_file = open("Data/pokemon.txt", "r+")
|
|
content = names_file.readlines()
|
|
return content
|
|
|
|
|
|
# Extract the name from a Pokemon extracted from the data file.
|
|
# Example: it will be read in from the data file as "150 Mewtwo\n" but it should just be "Mewtwo".
|
|
def trim_name(pokemon):
|
|
front_trim = 0
|
|
for char in pokemon:
|
|
if not char.isalpha():
|
|
front_trim += 1
|
|
else:
|
|
break
|
|
return pokemon[front_trim:-1]
|
|
|
|
|
|
# Find all the Pokemon who's names begin with a particular letter.
|
|
def pokemon_starting_with(char):
|
|
all_pokemon = load_names()
|
|
result = []
|
|
for pokemon in all_pokemon:
|
|
trimmed = trim_name(pokemon).lower()
|
|
if trimmed.startswith(char):
|
|
result.append(pokemon)
|
|
return result
|