Python Programming Questions

Python as an interview language: core syntax, data types and built-in collections, comprehensions, iterators and generators, idiomatic style, and the standard library, extending into data-oriented and automation use of the language and its common libraries. Covers writing correct, Pythonic code and reasoning about the language's semantics. The most heavily exercised language surface in this category across engineering and data roles.

MediumTechnical
25 practiced

Given two methods to read a large JSON lines file: (A) a single-threaded Python generator that parses line-by-line, and (B) a multi-process approach that splits file into byte ranges and parses in parallel, compare their performance trade-offs and pitfalls. When is B preferable and what are failure modes?

MediumTechnical
20 practiced

Write a function safe_import(module_name) that imports a module by name and returns a tuple (module_or_none, error_message_or_none). It should not raise exceptions to the caller, should capture ImportError, SyntaxError from broken packages, and handle long import times by using a timeout. Provide an implementation using standard library only.

MediumTechnical
26 practiced

Implement a function top_k_frequent(iterable, k) that returns the k most frequent items and their counts. Your solution must handle very large iterables (possibly streaming) and have O(n) expected time with O(k) additional memory where possible. Use Python.

MediumTechnical
23 practiced

A data pipeline intermittently produces different results on different runs (non-deterministic). List possible Python-language and library causes (e.g., dict ordering, floating-point reductions, parallelism) and propose concrete fixes to achieve determinism for production runs.

MediumTechnical
21 practiced

A Python automation script was fine in local testing, but month-end runs are now slow and use much more memory. How would you debug whether the problem is caused by repeated file reads, string processing, or keeping too much data in memory, and what would you change first?

Unlock Full Question Bank

Get access to all 46 Python Programming interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.