Get startedGet started for free

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 names list contains the names of each Pokémon in the sample.
  • The primary_types list containing the corresponding primary type of each Pokémon in the sample.
  • The generations list 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.

This exercise is part of the course

Writing Efficient Python Code

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Use the provided function to collect unique Pokémon names
uniq_names_func = ____(____)
print(len(uniq_names_func))
Edit and Run Code