Python rounds for analyst roles rarely ask about advanced computer science. They check that you are comfortable with the basics you will use every day. Here are the questions that come up most, with short answers you can explain in your own words.
Concept questions
List vs tuple
A list is mutable (you can add, remove and change items); a tuple is immutable. Tuples are used for fixed groups of values, such as a (latitude, longitude) pair, and can be dictionary keys because they cannot change.
List vs set
A list keeps order and allows duplicates. A set has no duplicates and very fast membership checks (x in my_set). Converting a list to a set is the quickest way to remove duplicates if order does not matter.
What is a dictionary?
A collection of key-value pairs with fast lookup by key. Keys must be unique and immutable. Dictionaries are ideal for counting, grouping and mapping codes to names.
Mutable vs immutable
Mutable objects (lists, dictionaries, sets) can be changed in place. Immutable ones (int, float, str, tuple) cannot; operations create new objects. A common bug: using a mutable default argument like def f(items=[]), which is shared between calls. Use None and create the list inside the function.
== vs is
== compares values; is checks whether two names point to the same object. Use is mainly for None checks: if x is None.
What does a list comprehension do?
It builds a list from a loop in one expression: [x * 2 for x in nums if x > 0]. It is usually clearer and faster than an equivalent loop with append.
*args and **kwargs
*args collects extra positional arguments into a tuple; **kwargs collects extra keyword arguments into a dictionary.
What is a lambda?
A small anonymous function written in one line: lambda x: x * 2. Common with sorted(key=...), map and pandas apply.
Short coding tasks
Count word frequency
def word_counts(text):
counts = {}
for word in text.lower().split():
counts[word] = counts.get(word, 0) + 1
return countsMention that collections.Counter does this in one line.
Reverse a string and check a palindrome
def is_palindrome(s):
s = "".join(ch.lower() for ch in s if ch.isalnum())
return s == s[::-1]Second largest number in a list
def second_largest(nums):
unique = sorted(set(nums), reverse=True)
return unique[1] if len(unique) > 1 else NoneAsk about duplicates and empty lists first; it shows care.
Merge two dictionaries, adding values for shared keys
def merge_add(a, b):
out = dict(a)
for k, v in b.items():
out[k] = out.get(k, 0) + v
return outFizzBuzz-style logic
Interviewers still use simple loop-and-condition tasks to see how you think. Talk through the conditions before typing.
How to answer well
- Ask about edge cases: empty input, duplicates, uppercase letters, negative numbers.
- Write readable code with clear names.
- Test it mentally on a tiny example.
- Mention a simpler built-in if one exists.
Practise
Our Python interview set covers these patterns, and the two practice tests (basics, functions and more) are good timed checks. For pandas questions, read pandas interview questions.
Practise what you just read
Reading helps; writing the code yourself is what sticks. Start here: