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
50 practiced
Design and implement a thread-safe, memory-efficient LRU cache in Python with a fixed capacity and optional TTL (time-to-live) per key. Do not use functools.lru_cache; standard library data structures are allowed. The cache must support get(key) and set(key, value) and be safe for concurrent access from multiple threads.
MediumTechnical
43 practiced
Implement a Python decorator `@memoize(maxsize)` that caches function results up to maxsize entries. The decorator should accept functions with positional and keyword arguments and evict least-recently-used entries when full. Use only the standard library (collections.OrderedDict is allowed). Discuss hashing of arguments and limitations with unhashable args.
MediumTechnical
62 practiced
Implement `parallel_map(func, iterable, workers)` in Python to apply a CPU-bound function to items in an iterable using multiprocessing. The function should return results in the same order as input and should handle picklable functions and inputs. Discuss pickling constraints and memory implications for large inputs.
HardTechnical
61 practiced
Discuss the risks of using pickle to serialize models and Python objects for production. Provide safer alternatives for persisting ML models (ONNX, joblib for scikit-learn, saving model weights), and show sample code that verifies a model artifact's integrity using a cryptographic hash and a signature before loading. Explain trade-offs between convenience and security.
EasyTechnical
48 practiced
Explain the idiom `if __name__ == '__main__':` in Python. Provide an example script that behaves differently when executed directly versus when imported as a module. In your answer, show a small example (script A) with a function and top-level test guarded by this idiom, and explain common uses in data-science projects (quick experiments, CLI entrypoints, running unit tests or example transforms).
Unlock Full Question Bank
Get access to hundreds of Python Fundamentals and Problem Solving interview questions and detailed answers.