Gathering unique Pokémon
A sample of 500 Pokémon has been created with replacement (meaning a Pokémon could be selected more than once and duplicates exist within the sample).
Three lists have been loaded into your session:
- The
nameslist contains the names of each Pokémon in the sample. - The
primary_typeslist containing the corresponding primary type of each Pokémon in the sample. - The
generationslist contains the corresponding generation of each Pokémon in the sample.
The below function was written to gather unique values from each list:
def find_unique_items(data):
uniques = []
for item in data:
if item not in uniques:
uniques.append(item)
return uniques
Let's compare the above function to using the set data type for collecting unique items.
Deze oefening maakt deel uit van de cursus
Writing Efficient Python Code
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Use the provided function to collect unique Pokémon names
uniq_names_func = ____(____)
print(len(uniq_names_func))