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.

HardTechnical
0 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.
HardTechnical
0 practiced
You have an ML preprocessing step that creates millions of small Python objects, causing memory spikes. Provide concrete, code-level strategies to reduce memory usage: using __slots__, using tuple instead of dict for small fixed records, using array.array or numpy for numeric arrays, switching lists to generators where possible, and pooling objects. For each suggestion, explain trade-offs and compatibility issues with existing code.
MediumTechnical
0 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.
HardTechnical
0 practiced
Implement a flexible Python decorator @retry_on_exception(retries=3, base_delay=0.1, exception_types=(Exception,), jitter=True) that supports both synchronous and asynchronous functions, preserves metadata with functools.wraps, uses exponential backoff with optional jitter, and allows an optional on_failure callback. Provide example usage for both sync and async functions and explain how to test it.
MediumTechnical
0 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.

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.