0
0
Pythonprogramming~5 mins

Why sets are used in Python - Quick Recap

Choose your learning style9 modes available
Recall & Review
beginner
What is a set in Python?
A set is a collection of unique items in Python. It automatically removes duplicates and is unordered.
Click to reveal answer
beginner
Why do we use sets instead of lists when we want unique items?
Sets automatically remove duplicates and are faster for checking if an item exists compared to lists.
Click to reveal answer
beginner
How do sets help in real life? Give an example.
Sets help when you want to find unique things, like unique guests invited to a party or unique words in a book.
Click to reveal answer
intermediate
What is one advantage of sets related to speed?
Sets are faster than lists for checking if an item is present because they use a special method called hashing.
Click to reveal answer
intermediate
Can sets be used to perform mathematical operations? Name one.
Yes, sets can perform operations like union, intersection, and difference to compare groups of items.
Click to reveal answer
What happens if you add duplicate items to a Python set?
ADuplicates are added multiple times
BDuplicates are ignored, only unique items remain
CAn error occurs
DDuplicates replace existing items
Which of these is a key benefit of using sets over lists?
AFaster membership testing
BMaintains order of items
CAllows duplicate items
DSupports indexing
Which operation can you perform with sets but not with lists?
AUnion
BAppending items
CIndexing
DSlicing
What type of data does a set store?
AOnly numbers
BOrdered items with duplicates
CUnique and unordered items
DOnly strings
Why might you use a set to find unique words in a sentence?
ABecause sets allow duplicates
BBecause sets keep words in order
CBecause sets sort words alphabetically
DBecause sets remove duplicates automatically
Explain why sets are useful when you want to store unique items.
Think about how sets handle duplicates and speed.
You got /3 concepts.
    Describe a real-life situation where using a set would be better than a list.
    Consider situations where duplicates are not wanted.
    You got /3 concepts.