Loading video player…

How to Stand Out in a Python Coding Interview (Overview)

You’ve made it past the phone call with the recruiter, and now it’s time to show that you know how to solve problems with actual code. Whether it’s a HackerRank exercise, a take-home assignment, or an onsite whiteboard interview, this is your moment to prove your coding interview skills.

But interviews aren’t just about solving problems: they’re also about showing that you can write clean production code. This means that you have a deep knowledge of Python’s built-in functionality and libraries. This knowledge shows companies that you can move quickly and won’t duplicate functionality that comes with the language just because you don’t know it exists.

At Real Python, we’ve put our heads together and discussed what tools we’re always impressed to see in coding interviews. This course will walk you through the best of that functionality, starting with Python built-ins, then Python’s native support for data structures, and finally Python’s powerful (and often underappreciated) standard library.

In this course, you’ll learn how to:

  • Use enumerate() to iterate over both indices and values
  • Debug problematic code with breakpoint()
  • Format strings effectively with f-strings
  • Sort lists with custom arguments
  • Use generators instead of list comprehensions to conserve memory
  • Define default values when looking up dictionary keys
  • Count hashable objects with the collections.Counter class
  • Use the standard library to get lists of permutations and combinations

Sample Code (.zip)

12.3 KB

Course Slides (.pdf)

273.2 KB

00:00 Hi, my name is James. In this course, you’ll learn how to stand out in a Python coding interview. This applies to coding challenges, technical phone screens, and onsite interviews.

00:10 You’ll learn a bunch of different data structures, built-in functions, and useful tips to really succeed in any Python coding interview. Let’s look at exactly what you’ll learn. In Section 1, you’ll learn about built-in functions.

00:23 These are functions that you don’t need to import, that can really help you during an interview—for example, enumerate() versus range().

00:31 enumerate() lets you iterate over the index and the element of an iterable, while range() just lets you iterate over the numbers.

00:38 You’ll also learn about list comprehensions and some useful built-in functions that you can apply on lists. List comprehensions aren’t exactly built-in functions—they’re more built-in syntax—but they’re a very Pythonic way to construct lists.

00:52 There are some built-in functions like max(), any(), and all() that can help you when working with lists. Then, you’ll learn about print() versus breakpoint()this can help you debug during an interview—f-strings, which aren’t really functions—more built-in syntax—that can show the interviewer that you know a very Pythonic way to construct strings—and then, sorting using the sorted() function.

01:17 In Section 2, you’ll leverage data structures, both built-in and that are included in the standard library: so, useful built-in data structure sets, which helps you check membership in constant time, generators, which help you iterate through a sequence in constant memory, and then, you’ll learn about dictionaries and the defaultdict, which help you create dictionaries with default values.

01:39 Then, you’ll learn about collections.Counter, which is a really easy one-line way to count how often elements appear in an iterable, collections.deque, which is a useful data structure where you can append to the left and right and pop off the left and right—all in constant time, and collections.namedtuple, which is a really clean way—and Pythonic way—to write immutable classes. In Section 3, you’ll learn about different built-in libraries and modules—for example, the string module, which includes a bunch of built-in string constants that you can use to find different things like all the lowercase letters in the alphabet.

02:15 itertools module helps you create iterators for efficient looping through sequences. Then, you’ll learn about the functools module, which has a bunch of higher order functions and properties that can really help you in an interview.

02:28 And then, finally, using doctest module and assert statements to help test your code and show the interviewer that you aren’t just using print statements to do all your testing. In Section 4, you’ll use what you learned in Section 1, 2, and 4 to solve a easy, medium, and hard interview question.

02:45 These are interview questions that you could definitely see in the real world. So, you’ll go through an easy interview question, something you might see on a coding challenge or maybe an interview for an internship, a medium level question that you might see on a phone screen or an onsite—depending on the company—and then you’ll go through a hard interview question, which is something you might see on a phone screen or an onsite.

03:04 You’ll see a brute force solution, a suboptimal solution, and then an optimized solution that uses the PriorityQueue data structure. The PriorityQueue is a useful abstract data type, which allows you to get the minimum value in logarithmic time.

03:19 Then, you’ll go over everything you learned. So, let’s jump right into enumerate() versus range().

Avatar image for Qasim Albaqali

Qasim Albaqali on April 22, 2020

This is such a good course! The content is superb, thank you :)

Avatar image for James Uejio

James Uejio RP Team on April 27, 2020

Thank you @Qasim!

Become a Member to join the conversation.