← Back to videos

Junior Python interview: dictionaries, hashes and mutable values

Interview timeline Click any block to jump

Interview breakdown

Interviewer verdict
Needs more practice Level: Intern (surface familiarity with fundamentals, below Junior)

Current depth and hands-on practice fall short of the Junior bar (suitable for an Intern role): the candidate has surface familiarity with collections and dicts, but wavers quickly on under-the-hood questions, flips positions under pushback, and missed the classic shared mutable default list trap in dict.fromkeys().

Candidate: Kirill
Target role: Junior Python Developer

28 y/o · dabbled in Python earlier, studying casually for ~1 year, 1st-year part-time IT student, no commercial experience

Answers accuracy 12 total
54% score
Theory
3/10 correct · 55%
Live coding
1/2 correct · 50%
Practical task
Partially solved

Creating a dict with dict.fromkeys(['a', 'b', 'c'], []) and mutating the shared list

On the first step, the candidate reasoned through dict being a built-in class and correctly predicted dict.fromkeys(['a', 'b', 'c'], []) returns {'a': [], 'b': [], 'c': []}. On the follow-up d['a'].append(1), he predicted a syntax error and, after seeing {'a': [1], 'b': [1], 'c': [1]}, could not explain that all keys reference the same list object.

Topics covered Click a topic to filter questions

Candidate strengths

  • + Familiarity with Python's core built-in collections (list, tuple, set, dict, frozenset) and insertion-ordered dicts
  • + Correctly deduced when a tuple is valid as a dict key (only when all nested elements are immutable/hashable)
  • + Recovered during code reading to conclude that dict is a built-in class (named in lowercase) with classmethod fromkeys()
  • + Constructive, self-aware attitude toward feedback and learning priorities

Areas to improve

  • → Move from passive course reading to active coding and hands-on experimentation with Python data structures
  • → Master Python's object reference model and shared mutability (why dict.fromkeys(keys, []) aliases one list across all keys)
  • → Understand hash table internals: integer hash() values, bucket indexing, and collision resolution
  • → Learn the iterator protocol (__iter__ / __next__) and the concept of idempotency

Questions in this interview

12 / 12
01 ▶ 03:24
What built-in collections exist in Python and what is their purpose?
Theory Collections, lists, dicts & hash tables
?
Candidate's answer

Listed lists, tuples, sets, dicts, and frozenset, explaining they group objects together for different access and storage needs.

Key takeaway

Python's built-in containers (list, tuple, dict, set, frozenset) trade off mutability, ordering, and lookup/insertion complexity.

Open moment on YouTube ↗
#01
02 ▶ 05:04
Is Python's dict an ordered collection, and what does ordering actually mean?
Theory Collections, lists, dicts & hash tables
?
Candidate's answer

Recalled that modern Python dicts are ordered unlike sets, initially confusing ordering with deterministic lookup before landing on insertion-order preservation during iteration.

Key takeaway

Since Python 3.7, dict officially guarantees insertion-order preservation during iteration, while remaining a key-value mapping rather than an integer-indexed sequence.

Open moment on YouTube ↗
#02
03 ▶ 08:18
What is iteration, what makes an object iterable, and must every iterable be a collection?
Theory Decorators, iterators, generators & context managers
?
Candidate's answer

Correctly tied iterability to the __iter__ dunder method and mentioned strings, but could not name a non-collection iterable.

Key takeaway

Any object implementing __iter__ is iterable — including lazy streams like generators, open file objects, map/filter, and range that are not materialized collections.

Open moment on YouTube ↗
#03
04 ▶ 11:34
How can you iterate through a collection in Python besides a for loop?
Theory Control flow, loops & syntactic sugar
?
Candidate's answer

Named for and while loops and vaguely referenced calling an underlying iteration method directly without naming iter() and next().

Key takeaway

Under the hood, iteration calls iter(obj) and repeatedly invokes next(it) until StopIteration — used by for loops, comprehensions, unpacking, and consumers like list() or sum().

Open moment on YouTube ↗
#04
05 ▶ 13:36
What does a Python dictionary consist of, how does it differ from a list, and why do we need it?
Theory Collections, lists, dicts & hash tables
?
Candidate's answer

Briefly described a list by mistake, then corrected to key-value pairs with custom keys and faster lookup than scanning lists, though with hesitant phrasing.

Key takeaway

A dict implements an associative mapping with average O(1) key lookup, insertion, and deletion, versus O(n) value scans in a list.

Open moment on YouTube ↗
#05
06 ▶ 20:04
What restrictions apply to dictionary keys and values in Python?
Theory Collections, lists, dicts & hash tables
?
Candidate's answer

Correctly stated that values can be arbitrary objects while keys must be immutable/hashable.

Key takeaway

Dict values are unrestricted, whereas keys must be hashable — providing a stable __hash__() value and __eq__() comparison.

Open moment on YouTube ↗
#06
07 ▶ 22:50
What is a hash in Python, how does dict's hash table use it, and are hashes guaranteed to be unique?
Theory Collections, lists, dicts & hash tables
?
Candidate's answer

Described a hash as a low-level bit representation and wrongly claimed hashes never repeat, struggling to explain bucket lookup.

Key takeaway

hash(key) returns a fixed-width integer used to compute a table slot index; hash collisions are normal and resolved in CPython via open addressing plus == equality checks.

Open moment on YouTube ↗
#07
08 ▶ 26:40
Can a tuple be used as a dictionary key in Python?
Theory Collections, lists, dicts & hash tables
?
Candidate's answer

After brief hesitation, reasoned accurately that a tuple is a valid dict key if and only if all of its elements are themselves immutable/hashable.

Key takeaway

A tuple is hashable only when every element inside it is recursively hashable; (1, [2, 3]) raises TypeError: unhashable type: 'list'.

Open moment on YouTube ↗
#08
09 ▶ 29:02
What are the different ways to create a dict and a set in Python?
Theory Collections, lists, dicts & hash tables
?
Candidate's answer

Named {}, dict comprehensions, and dict(), and correctly noted empty {} creates a dict so an empty set requires set(), while omitting non-empty set literals {1, 2}.

Key takeaway

Empty {} always creates an empty dict (so empty sets require set()), whereas non-empty sets also support {1, 2} literals and set comprehensions.

Open moment on YouTube ↗
#09
10 ▶ 30:25
Are built-in dict and set functions or classes in Python?
Theory OOP, classes & dunder methods
?
Candidate's answer

Wavered between function, class, and method before wrongly settling on dict being a built-in function during the theory section.

Key takeaway

int, str, list, tuple, dict, and set are built-in classes (instances of type) named in lowercase by convention; calling dict() instantiates the class.

Open moment on YouTube ↗
#10
11 ▶ 35:17
Will d = dict.fromkeys(['a', 'b', 'c'], []) work, what does it return, and what is dict.fromkeys?
Live coding Collections, lists, dicts & hash tables
?
Candidate's answer

Overcame initial doubt about lists, recognized dict as a built-in class with classmethod fromkeys, and accurately predicted {'a': [], 'b': [], 'c': []}.

Key takeaway

The classmethod dict.fromkeys(iterable, value=None) builds a new dictionary mapping each key from iterable to value.

Open moment on YouTube ↗
#11
12 ▶ 44:46
After d = dict.fromkeys(['a', 'b', 'c'], []), what does d['a'].append(1); print(d) output, and why?
Live coding Data types, numbers & memory
?
Candidate's answer

Predicted a syntax error (or mutating only key 'a') and could not explain why {'a': [1], 'b': [1], 'c': [1]} appeared when run.

Key takeaway

dict.fromkeys(['a', 'b', 'c'], []) evaluates [] once and binds every key to that single shared list reference; use {k: [] for k in ['a', 'b', 'c']} to allocate distinct lists.

Open moment on YouTube ↗
#12
Original video description & timecodes

A mock interview for the role of Junior Python Developer. In this review, the candidate answers basic questions about Python: collections, dictionaries, iteration, hash tables, dictionary keys, creating dictionaries, and how code behaves with default values. At the end, there is detailed feedback analysing the candidate’s strengths, mistakes and areas for improvement.

Timecodes:
00:00 Start
00:11 Greeting and introduction
01:31 Interview format and rules
03:24 Question about collections in Python
05:04 Dictionaries as collections: ordering and features
08:18 What is iteration?
11:34 How to iterate over collections
13:36 How a dictionary works
20:51 Hash, hash tables and dictionaries in Python
26:18 What are the restrictions on dictionary keys
29:02 Ways to create a dictionary and a set
35:00 Code review with a dictionary
53:36 Moving on to feedback
56:21 Detailed feedback from the interviewer