What does the list method append(x) do?
Adds x to the end of the list.
What does the list method extend(iterable) do?
Appends all items from an iterable to the list.
What does the list method insert(i, x) do?
Inserts x at index i.
What does the list method remove(x) do?
Removes the first occurrence of x; raises ValueError if not found.
What does the list method pop([i]) do?
Removes and returns item at index i; removes last item if i not given.
What does the list method clear() do?
Removes all items from the list.
What does the list method index(x[, start[, end]]) do?
Returns the first index of x, optionally within start and end.
What does the list method count(x) do?
Counts how many times x appears in the list.
What does the list method sort(key=None, reverse=False) do?
Sorts the list in place.
What does the list method reverse() do?
Reverses the list in place.
What does the list method copy() do?
Returns a shallow copy of the list.
Do mutating list methods return a value?
No, they return None.
Can lists with mixed incomparable types be sorted?
No, lists with incomparable types cannot be sorted.
How can a list act as a stack?
By using append() to push and pop() to pop.
Why aren’t lists ideal as queues?
Because pop(0) is inefficient due to element shifting.
What should be used for efficient queues?
collections.deque for O(1) operations on both ends.
What is a list comprehension?
A concise way to build a new list from an iterable with optional conditions.
How does a nested list comprehension work?
It allows an inner comprehension within the expression.
What does the del statement do?
Deletes an item, slice, or entire variable without returning a value.
What is a tuple?
An immutable, ordered sequence of values separated by commas.
Can tuples contain mutable objects?
Yes, tuples can hold mutable objects.
How do you define a one-element tuple?
With a trailing comma, e.g. (‘item’,)
What is tuple packing?
Assigning multiple values into a single tuple.
What is sequence unpacking?
Assigning individual elements of a sequence to separate variables.