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
59 practiced
You inherit a model training loop class that directly opens files, seeds random globally, and instantiates heavy dependencies inside methods making it hard to unit test. Refactor this design to improve testability: show a before-and-after code sketch where you inject data loaders, rng, and persistence handlers. Explain how dependency injection and small interfaces improve unit testing and CI reliability for model code.
HardTechnical
59 practiced
Explain the Global Interpreter Lock (GIL) in CPython and its implications for multi-threaded data processing. Provide strategies to parallelize CPU-bound computations in Python (multiprocessing, C extensions, numpy vectorization, joblib) and include a small code example showing how to parallelize a CPU-bound NumPy operation safely.
HardTechnical
57 practiced
Design a small DSL in Python to build composable filters for tabular data. Example API:
python
q = (Q('age') > 30) & (Q('country') == 'US' | Q('country') == 'CA')
print(q.to_sql())  # -> "(age > %s) AND ((country = %s) OR (country = %s))"
Implement a minimal `Q` class supporting __eq__, __gt__, __and__, __or__ and a `to_sql()` method that produces a parameterized WHERE clause and a list of parameters. Discuss SQL injection mitigation and how to extend to IN, NOT, and LIKE.
HardTechnical
49 practiced
You maintain a function `normalize(data: dict)` that recursively converts numeric-like strings into numbers and normalizes keys (lowercase, underscore). Design unit tests using pytest and write at least two property-based tests using Hypothesis that assert invariants (e.g., normalization idempotence, keys normalized). Provide sample test cases and explain how Hypothesis strategies can generate nested dicts.
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.

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.