

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 5
click for more info
Not enough gems
Cost: 6 gems
1: Sets
incomplete
2: Sets Quiz
incomplete
3: Vowels
incomplete
4: Set Subtraction
incomplete
This lesson's interactive features are locked, please to keep using them
Sets are like Lists, but they are unordered and they guarantee uniqueness. Only ONE of each value can be in a set.
fruits = {"apple", "banana", "grape"}
print(type(fruits))
# Prints: <class 'set'>
print(fruits)
# Prints: {'banana', 'grape', 'apple'}
You can .add() values to a set. Think of .add() like append but for sets!
fruits = {"apple", "banana", "grape"}
fruits.add("pear")
print(fruits)
# Prints: {'pear', 'banana', 'grape', 'apple'}
No error will be raised if you add an item already in the set, and the set will remain unchanged.
Because the empty bracket {} syntax creates an empty dictionary, to create an empty set, you need to use the set() function.
fruits = set()
fruits.add("pear")
print(fruits)
# Prints: {'pear'}
fruits = {"apple", "banana", "grape"}
for fruit in fruits:
print(fruit)
# Prints:
# banana
# grape
# apple
Note: Sets are unordered, so the order of iteration is not guaranteed.
Complete the remove_duplicates function. It should take a list of spells that a player has learned and return a new List where there is at most one of each title. You can accomplish this in at least two ways:
Iteration:
Set conversion:
It makes no sense to learn a spell twice! Once it's learned, it's learned forever.