Junior Codes
The Treasure Archive

Python Sets for Kids: Removing Duplicates

Keep only unique values and compare groups quickly.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

Sets, explained simply

A set is a collection where every item appears only once. If you add something that is already there, nothing changes. That makes sets perfect for removing duplicates.

You can turn a list into a set with set(my_list). Sets do not keep items in order, so you cannot use an index with them.

Sets are great for questions like "is this in the group?" using in, and for comparing groups: & finds items in both, | combines them.

Example: Find the unique gems

found = ["ruby", "opal", "ruby", "jade", "opal"]
unique = set(found)
print(len(found), "found,", len(unique), "different")
print("jade" in unique)

Output

5 found, 3 different
True

Try this

  • Find the different letters in the word "banana".
  • Make two sets of hobbies and print the ones you and a friend share using &.
  • Add an item twice with .add() and check the length.

Practise it in Wonderwild

“The duplicate gem mystery”

Mission 23 in The Treasure Archive, one of 36 Python missions in Wonderwild.

Your child writes and runs real Python in the browser while Pip reacts to every line. Nothing to install. For ages 7+.

Start Wonderwild free with Pip

Try 5 starter activities free. Full access is ₹499 a year.

This mission is part of full access. The first missions are free to try.

Questions parents and kids ask

Why does my set print in a different order?+

Sets do not remember order. Python arranges them in whatever way makes lookups fast. Use a list if order matters.

How do I make an empty set?+

Write set(). Empty curly brackets {} make an empty dictionary, not a set.

Prefer learning with a teacher?

Our live Python for Young Developers course teaches these ideas in small online classes led by a software engineer, with projects and feedback. Every live course also includes 12 months of full Wonderwild access for practice.

See the Python for Young Developers course