Articles
The problem...
You have a list of names. Some appear more than once.
attendees = ["Raven", "Wolf", "Raven", "Ghost", "Wolf", "Bull"]
You want only the unique names. No duplicat…
The idea
You know what a set is and why it exists.
Now let's look at what you can actually do with one — adding, removing, checking, and comparing.
Adding and removing el…
What you're building
An attendance tracker. You have a fixed list of enrolled students. The user marks who showed up. At the end — present, absent, numbers.
What you need …
The problem...
You want a list of squares for numbers 1 through 10.
The loop version works:
squares = []
for n in range(1, 11):
squares.append(n ** 2)
print(squares)
Ou…
The idea
You know the syntax. Now let's put it to work — with lists and sets, across real scenarios.
The only difference between a list comprehension and a set comprehensi…
The idea
Same concept as list and set comprehensions — but now you're building a dict.
Every element produces a key-value pair instead of just a value.
The syntax
{key_e…