Level 7: Sets - IncrediCoders/Python1 GitHub Wiki

Syntax Turtle added this page on June 6, 2025
Here is a bonus article that will tell you more about Sets!
In addition to this bonus article, you can find other bonus articles that teach you the topics I covered in Level 7: Dictionaries and Classes.
A set is like a collection of things, but with no repeats. In programming, a set is a group of items where each one is unique, and the order doesn't matter. You can use a set when you only care what’s there, not how many times it shows up or the order it’s in.
[TO DO: Our book's relationship with Sets. Do we show this a little in Level 7 but don't call out that they're sets? Or do we not do Sets at all? Then we explain here what we do instead (like Lists) and how Sets are different. When you'd want to use Sets versus Lists, Variables, etc.]
Sets help you clean up data and find what's different, shared, or missing between groups. They're great when you want to check for duplicates or make sure there aren’t any. You can also use sets to find what items two groups share or don’t share.
In Python, a set is made with curly braces {}
, just like a dictionary, but only with values, not key-value pairs.
Scenario: Paul Python collects pet names from his class.
pets = {"dog", "cat", "hamster", "cat", "dog"}
print(pets)
This will print:
{'dog', 'cat', 'hamster'}
What does this mean: Even though "dog" and "cat" were listed twice, the set only keeps one of each.
All three languages, Python, Java, and C#, have sets. They may look different, but they all make sure no item is repeated.
Scenario: We want to store a list of favorite fruits without repeats.
Python
fruits = {"apple", "banana", "apple"}
print(fruits)
# This will print: {'apple', 'banana'}
Java
import java.util.HashSet;
HashSet<String> fruits = new HashSet<>();
fruits.add("apple");
fruits.add("banana");
fruits.add("apple");
System.out.println(fruits);
C#
using System.Collections.Generic;
HashSet<string> fruits = new HashSet<string>();
fruits.Add("apple");
fruits.Add("banana");
fruits.Add("apple");
Console.WriteLine(string.Join(", ", fruits));
What’s the Difference?
- Python uses curly braces
{}
to create sets and automatically removes repeats. - Java and C# use something called
HashSet
, and you use.add()
to put things in.
TBD
Next, you can take on the two extra challenges to build more features for the IncrediCards game, and to learn more!
-
Challenge 1: In this challenge, you are going to add two more cards to each player's deck, so that you can switch between five cards (instead of three cards).
-
Challenge 2: In this second challenge, you are going to add a second attack option, the Coded Attack (which has special abilities, like to get an extra turn).
-
Level 7: Unplugged Activity - I wrote this page with more details than what you saw in the book. In this game,
-
Level 7: Rewards - If you completed the IncrediCards program that we talked about, then I set up this page to act as a reward. You can see some illustrations of me and learn more about who I am! You'll also find the WHAT Award digital download, to show off your accomplishment!
-
Level 7: IncrediCards - All Online Resources - Return back to the main Level 7 page, with all our online resources!
After you're completely done with Level 6 (did you do the challenges?), then it's time to move on to Level 7! While you read through Level 7 in your book, you can check out the resources from CHARACTER, as he teaches you how to build the IncrediCards program:
Syntax and I love to make card games like IncrediCards! We hope you had fun learning about it too!
--Grafika and Syntax Turtle