You're on assignment part 3/3 for this lesson.
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", "apple"}
print(type(fruits))
# Prints: <class 'set'>
print(fruits)
# Prints: {'banana', 'grape', 'apple'}
You can .add() values to a set.
fruits = {"apple", "banana", "grape"}
fruits.add("pear")
print(fruits)
# Prints: {'banana', 'grape', 'pear', '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
fruits = {"apple", "banana", "grape"}
fruits.remove("apple")
print(fruits)
# Prints: {'banana', 'grape'}