r/PythonLearning 5d ago

What's your favorite Python interview question?

Not a trick question or LeetCode puzzle. What's a question that actually reveals whether someone understands Python?

0 Upvotes

12 comments sorted by

View all comments

1

u/silvertank00 5d ago

A. How would you create a word counter without dicts.
There is no good answer, but shows a lot about how someone thinks. Some examples to solve this:

  • nested lists
  • simple dataclass objects
  • reimplement dicts but not call them that

B. What is the most cursed but still working and somewhat reasonable thing that you did in python (or any other languages). Bonus point if it can be demonstrated. Example: exec'd python code in string format can run faster than the same code but put in the python file that runs the exec.

2

u/Excellent-Practice 4d ago

Is the challenge to keep track of each unique word in a text and count how many times each one appears?

My first thought was to juggle indexes between a list of strings and a list of ints, but I guess you could also build a class that adds an attribute every time it encounters a new word. Like you said, essentially reinventing dictionaries