InterviewStack.io LogoInterviewStack.io

Python Fundamentals and Problem Solving Questions

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.

MediumTechnical
58 practiced
Implement an LRUCache class in Python with methods get(key) and put(key, value) that both run in O(1) time. The cache should support a fixed capacity and evict the least-recently-used item when full. Implement it using only the standard library (collections.OrderedDict or a custom doubly-linked list + dict). Explain how an ML pipeline might use this to cache preprocessed feature vectors and avoid repeated computation.
MediumTechnical
59 practiced
Given a list of dictionaries representing dataset rows, implement stratified_split(rows, label_key, train_frac, val_frac, test_frac, seed) in Python that splits the rows into train/val/test lists stratified by label_key and reproducible using the seed. Handle labels with very few samples and document your chosen behavior (e.g., minimum samples per split or assignment policy).
MediumTechnical
45 practiced
Write a Python generator function flatten(iterable) that takes a nested iterable of arbitrary depth (for example: [1, [2, 3], (4, [5, [6]])]) and yields scalar elements lazily without building the flattened list in memory. The function should treat str and bytes as atomic elements (not to be flattened). Provide tests demonstrating the generator behavior.
EasyTechnical
47 practiced
Describe the purpose and differences between __init__, __repr__, and __str__ methods in Python classes. Provide a concise example of a lightweight ModelWrapper class for an ML model that implements these methods to aid debugging and readable logging in production environments.
MediumTechnical
48 practiced
Compare Python's built-in list, collections.deque, and array.array for queue-like operations commonly used in ML data pipelines (append/pop from both ends). Discuss performance characteristics (amortized bounds), memory usage, and when to prefer each. Propose a simple micro-benchmark to compare them for your expected workload.

Unlock Full Question Bank

Get access to hundreds of Python Fundamentals and Problem Solving interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.