PART 7 · PRACTICE, PREP FLOW AND REVISION
Concept questions with short answers
FreeLesson 75 of 78
The no-keyboard part of the round. Answer in two sentences, then give one example from the store data.
List vs tuple? Lists are mutable, tuples are not. Tuples can be dict keys and signal "fixed record".
How do you read a 50 GB file? Stream it: iterate lines or use chunks (P13), never read() it whole. Or move to Spark.
is vs ==? is checks identity (same object), == checks value. Use is only for None, True, False (page 26).
JSON vs JSON Lines? JSON is one document you load whole. JSON Lines is one record per line, so you can stream and split it.
Why is a mutable default argument a bug? Defaults are created once at def time, so every call shares the same list (page 26).
Why parameterized SQL? Values go separately from the query text, which prevents SQL injection and quoting bugs (page 71).
Shallow vs deep copy? Shallow copies the outer container only; nested objects are still shared. deepcopy copies everything.
apply vs vectorized in pandas? apply calls Python per row; vectorized runs compiled code on whole columns, far faster (page 70).
Why are dict and set lookups O(1)? Keys are hashed to a slot, so lookups do not scan. That is why keys must be hashable.
Generator vs list? A generator yields one item at a time and can be used once. A list holds everything and can be reused (page 35).
Iterator vs iterable? An iterable can give you an iterator (iter()). An iterator gives values with next() until StopIteration.
What does yield from do? Passes every value from a sub-generator through, which keeps recursive generators short.
What is a decorator? A function that takes a function and returns a wrapped one. Used for timing, retries, logging, caching (page 38).
Why functools.wraps? It copies the name and docstring onto the wrapper, so logs and tools see the real function.
What is a context manager? An object with __enter__/__exit__ used with "with". Cleanup runs even when the block raises.
*args and kwargs?** Extra positional arguments as a tuple and extra keyword arguments as a dict (page 31).
What is the GIL? A lock that lets one thread run Python bytecode at a time. Threads still help for I/O (page 39).
Threads vs processes vs asyncio? Threads for blocking I/O, processes for CPU work, asyncio for very many concurrent I/O calls.
Why Decimal for money? Floats store binary approximations, so 0.1 + 0.2 is not 0.3. Decimal is exact in base 10 (page 27).
What is a dataclass? A class whose __init__, __repr__ and __eq__ are generated from typed fields. frozen=True makes it read-only.
EAFP vs LBYL? Try and catch the error vs check first. Python leans EAFP; it avoids race conditions between the check and the use.
loc vs iloc? loc selects by label and boolean mask, iloc by integer position.
merge vs concat? merge joins on keys like SQL JOIN. concat stacks frames like UNION ALL.
Why does groupby lose rows? NaN keys are dropped by default. Use dropna=False or fill them (page 70).
Parquet vs CSV? Parquet is columnar, typed and compressed, so it is smaller and reads only needed columns. CSV is plain text with no types.
What makes a pipeline idempotent? Rerunning gives the same result: overwrite a partition or MERGE on a key, never blind append (page 72).
logging vs print? logging has levels, names and formats, and can be routed and filtered. print cannot.
What does if __name__ == "__main__" do? Runs code only when the file is executed, not when imported. Needed for multiprocessing.
Unit test vs data quality check? Unit tests check code on fixed inputs. DQ checks check real data on every run (page 73).
pandas vs PySpark? pandas runs eagerly on one machine. PySpark runs lazily across a cluster when data outgrows one machine (page 74).
What does Big-O measure? How the work grows as the input grows, not seconds. Drop constants, keep the biggest term (page 41).
What counts as space complexity? Extra memory beyond the input: new collections, and the call stack for recursion (page 42).
BFS vs DFS? BFS uses a queue and goes level by level (shortest steps). DFS uses a stack or recursion and goes deep first (page 53).
When is greedy wrong? When a locally best step blocks a better total, like coins [1, 3, 4] for 6. Then use DP (page 56).
Practice before you move on
- Answer each question out loud in under a minute before you read the short answer.
- Write a short snippet that proves one of the answers and run it.