InterviewStack.io LogoInterviewStack.io

Python Fundamentals and Core Syntax Questions

Comprehensive knowledge of core Python language features and syntax, including primitive and composite data types such as integer numbers, floating point numbers, strings, booleans, lists, dictionaries, sets, and tuples. Candidates should understand variable assignment and naming, operators for arithmetic, logical, and comparison operations, and control flow constructs including conditional statements and loops. Expect familiarity with function definition, invocation, parameter passing, return values, and scope rules, as well as common built in functions and idioms such as iteration utilities, list comprehensions, generator expressions, and basic functional utilities like map and filter. Candidates should demonstrate error and exception handling techniques and best practices for writing readable and maintainable code with modularization and clear naming. Practical skills include file input and output, working with common data formats such as comma separated values and JavaScript Object Notation, selecting appropriate data structures with attention to performance and memory characteristics, and applying memory efficient patterns for processing large data sets using iterators and generators. Familiarity with the standard library and common utilities for parsing and transforming data, and the ability to write small code snippets to solve algorithmic and data manipulation tasks, are expected.

EasyTechnical
70 practiced
Write increment_nested_counter(store, key1, key2, delta=1) in Python 3 that safely increments nested counters represented as a dict-of-dicts, leveraging collections.defaultdict to simplify initialization. Show how you would initialize such a store and explain why this pattern is useful in ETL aggregation code.
HardTechnical
86 practiced
Implement top_k_frequent(iterable, k) in Python 3 that returns the k items with highest frequency along with counts. Provide an exact solution that works when unique key count fits in memory and then describe approximate strategies (e.g., Count-Min Sketch, lossy counting) when cardinality is too high. Explain time and memory trade-offs.
MediumTechnical
65 practiced
Implement a Python 3 generator function stream_csv_dicts(path) that yields rows from a CSV file as dicts using csv.DictReader. The generator must be memory efficient, close resources properly when iteration ends or is aborted, and support very large files. Explain pros/cons of placing 'with open' inside the generator and how to guarantee file closure.
MediumTechnical
84 practiced
Implement reservoir sampling in Python 3: write reservoir_sample(iterable, k) that returns k uniformly random items from an iterator of unknown and huge length, using only O(k) memory and a single pass. Explain why the algorithm yields a uniform sample from the stream.
MediumTechnical
86 practiced
Write Python 3 code that reads a large NDJSON file and writes a standard JSON array to an output file without loading all objects into memory. Ensure proper JSON formatting (commas between items, no trailing comma). Discuss how to make the write atomic and how to test this behavior.

Unlock Full Question Bank

Get access to hundreds of Python Fundamentals and Core Syntax interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.