What is the difference between break and continue?
break → immediately exits the entire loop.
continue → skips the rest of the current iteration and moves to the next one.
{1,2}.intersection({2,3})
{2}
What does "while (False):" do?
It never runs - the loop body is skipped entirely.
Is the following a valid container:
{[1,2]: 3, [4,5]: 6}
No — it’s not valid.
Dictionary keys must be immutable and hashable.
Which loop should we use for the game guess_the_number if we do not limit the number of attempts?
Use a while loop, since it can run indefinitely until the correct number is guessed.
Write 1 line to print the number of unique characters in mystr.
print(len(set(mystr)))
This built-in function gets both index and value when iterating a sequence.
enumerate()
Classify the following as mutable or immutable:
Tuple, list, set, dictionary
Tuple: Immutable
List: Mutable
Set: Mutable
Dictionary: Mutable
When iterating a list of (a, b) pairs, you can write "for a, b in pairs:" — this feature is called what? Example: pairs = [(1,2), (3,4)]
tuple unpacking
sorted({"a": 1, "b": 0}, reverse=True)
['b', 'a']