Algorithms

How to Filter a Dictionary in Python? (… The Most Pythonic Way)

Problem: Given a dictionary and a filter condition. How to filter a dictionary by … … key so that only those (key, value) pairs in the dictionary remain where the key satisfies the condition? … value so that only those (key, value) pairs remain where the value satisfies the condition? In this tutorial, you’ll learn …

How to Filter a Dictionary in Python? (… The Most Pythonic Way) Read More »

Complexity of Python Operations

In this tutorial, you’ll learn the runtime complexity of different Python operations. Then, you’ll learn how to calculate the complexity of your own function by combining the complexity classes of its constituents. This is called “static analysis” The tutorial is loosely based on (source) but it extends it significantly with more practical examples, interactive snippets, …

Complexity of Python Operations Read More »

Google’s FooBar Challenge | See How I Passed Levels 1 to 5 in Real-Time

I just got invited to perform Google’s FooBar challenge. In this article, I want to share with you how I solved the problems in real-time. The purpose of this article is to educate you—and to have some fun. So, are you ready? Level 1: Prime Numbers The first goal was to find an identifier for …

Google’s FooBar Challenge | See How I Passed Levels 1 to 5 in Real-Time Read More »

The Most Pythonic Way to Check if a Python String Contains Another String? (Tutorial + Video)

How to check if a Python string s1 contains another string s2? There are two easy ways to check whether string s1 contains string s2: Use the expression s2 in s1, or Use the find method s1.find(s2). You can try both methods in our interactive Python shell (just click “Run” to execute the code in …

The Most Pythonic Way to Check if a Python String Contains Another String? (Tutorial + Video) Read More »

How to Sum List of Lists in Python? [Rows]

Problem: Given a list of lists representing a data matrix with n rows and m columns. How to sum over the rows of this matrix? In this article, you’re going to learn different ways to accomplish this in Python. Let’s ensure that you’re on the same page. Here’s a graphical representation of the list of …

How to Sum List of Lists in Python? [Rows] Read More »

How to Sum List of Lists in Python? [Columns]

Problem: Given a list of lists representing a data matrix with n rows and m columns. How to sum over the columns of this matrix? In this article, you’re going to learn different ways to accomplish this in Python. Let’s ensure that you’re on the same page. Here’s a graphical representation of the list of …

How to Sum List of Lists in Python? [Columns] Read More »

How to Remove Duplicates From a Python List of Lists?

What’s the best way to remove duplicates from a Python list of lists? This is a popular coding interview question at Google, Facebook, and Amazon. In this article, I’ll show you how (and why) it works—so keep reading! How to remove all duplicates of a given value in the list? Method 1: Naive Method Algorithm: …

How to Remove Duplicates From a Python List of Lists? Read More »