30. Quiz: Sets

Quiz: list to set

Sets I

What would the output of the following code be?

a = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
b = set(a)
print(len(a) - len(b))
SOLUTION: 6

Quiz: add and pop

Sets II

Consider the following code:

a = [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]
b = set(a)
b.add(5)
b.pop()

After executing this code, will the number 5 be a part of the set b?

SOLUTION: Maybe

Set Playground

Start Quiz:

## You may test any code out here. Use Test Run to see your output