3 handy Python tricks for code interviews

Jason Curtis
Option Zero
Published in
1 min readJan 21, 2020

Some Python tricks that will help you impress your interviewer.

1. Heapq

As the standard implementation of a heap, heapq is an essential Python module to know. Its interface is also a little unusual for the standard library. Practice using it.

Example code:

2. Hypothesis

Hypothesis handy testing tool that generates test cases for you. You should still know what specific test cases you’re looking for, but throwing hypothesis in there can be a nice finishing touch. This is not in the standard library, so you should check if it’s permissible.

Simple example of how to use the hypothesis library

3. Bisect

Bisect is standard library tool that implements binary search. I’d generally reach for it instead of implementing binary search by hand. The interviewer may want to see you implement your own binary search, in which case you should be ready to do so, but bisect is the “real” way to do it.

Simple example of how to use bisect in Python

--

--