Comprehensive knowledge of the Python programming language, idiomatic usage, and the ability to implement correct, readable, and testable solutions to coding problems. Core language elements include syntax and semantics, primitive and composite data types such as integers, floats, strings, lists, dictionaries, sets, and tuples, sequence and mapping operations, control flow constructs, functions and closures, and object oriented programming basics including classes, instances, inheritance, and special methods. Additional practical topics include error and exception handling, file input and output operations, comprehensions and generator expressions, generator functions and iteration protocols, context managers, lambda functions, unpacking, and common standard library utilities. Candidates should understand algorithmic time and space complexity for common operations, typical performance characteristics of lists and dictionaries, and common pitfalls such as mutable default arguments and shared mutable state. Interview focused expectations include writing clean correct code without editor assistance, sensible variable naming, implementing basic algorithms and data structure manipulations under time constraints, reasoning about tradeoffs and complexity, and demonstrating testability and code quality.
HardTechnical
49 practiced
Design and implement a memory-efficient strategy in Python to compute TF-IDF features for the top K=100000 terms from a corpus too large to fit in memory. Discuss the trade-offs between an exact two-pass algorithm (term counting then compute IDF) and single-pass approximations (hashing trick, online IDF estimators), data structures for sparse vectors, and provide code sketches for streaming counting and building sparse feature vectors for training.
MediumTechnical
55 practiced
Write a Python function merge_sorted_by_timestamp(a, b) that takes two iterables of (timestamp, payload) tuples (ascending timestamps) and yields merged tuples in timestamp order. The implementation should be lazy (a generator), stable for equal timestamps, and run in O(n+m) time using minimal extra memory. Include a usage example.
MediumTechnical
46 practiced
Discuss why loading pickle files from untrusted sources is dangerous, and implement a safe_load_model(path, allowed_classes=None) function in Python that attempts to validate or restrict deserialization. Present safer alternatives to pickle for model serialization (ONNX, SavedModel, joblib with restrictions) and trade-offs for portability and performance.
HardTechnical
50 practiced
You have flaky unit tests caused by code that depends on current time and randomness. Design a robust testing strategy in Python to make tests deterministic: show examples using unittest.mock.patch or monkeypatch to control time and randomness, using freezegun to freeze time, and seeding RNGs in setup. Explain how to avoid masking real race conditions and how to test async code with simulated timeouts.
EasyTechnical
61 practiced
Explain the mutable default argument pitfall in Python with a concrete code example that demonstrates the bug (for example: def append_item(x, lst=[]): ...). Rewrite the example to avoid the issue and explain why the fixed version works. Discuss how the bug might appear in a long-running ML service that accumulates state across requests and how to detect it.
Unlock Full Question Bank
Get access to hundreds of Python Fundamentals and Problem Solving interview questions and detailed answers.