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.

MediumTechnical
0 practiced
Explain Python scoping rules (LEGB: Local, Enclosing, Global, Built-in). Provide a concrete example showing a closure capturing a loop variable incorrectly when creating functions in a loop, and demonstrate two ways to fix the problem.
HardTechnical
0 practiced
Implement the Misra-Gries algorithm (a deterministic k-heavy hitters algorithm) in Python to find items that may appear more than n/k times in a stream. The function should accept an iterable and k and return candidate items and their estimated counts. Discuss algorithm accuracy and memory guarantees.
HardTechnical
0 practiced
Implement a Python iterator class Peekable that wraps any iterator and supports peek() to view the next element without consuming it, and pushback(value) to place a value back into the stream so subsequent next() returns it. Ensure correct behavior for multiple pushes and for an exhausted underlying iterator.
HardTechnical
0 practiced
Write a Python function external_merge_sort(file_paths, output_path, key_index=0) that performs an external merge sort across multiple large CSV files that do not fit into memory. Describe how to split files into sorted chunks, write temporary files, perform a k-way merge (using heapq.merge or similar), and clean up temporary files safely.
MediumTechnical
0 practiced
You must one-hot encode a categorical column with 50,000 distinct categories for a model, but memory is limited. Using core Python primitives and standard-library strategies, outline a memory-efficient representation approach (for example sparse mapping, hashing trick, streaming) and discuss trade-offs for accuracy, interpretability, and memory.

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.