Get a list of Class Attributes in Python

In Python, Object-Oriented Programming (OOP) is based on classes that are used to create new objects easily. This is where we will define the methods and attributes linked to an object. If we create a new class, called Human(), where…

How to Flatten a List in Python

As we often explain, the list is one of the most used data types in Python. Sometimes, we can have what is called a two-dimension list, also referred to as nested lists or list of lists. For example: This structure…

Lowercase a String in Python

When you’re dealing with strings in Python, you may want to convert them to lowercase. This is a standard practice to ensure that your data is consistent and that you don’t hold, unwillingly, duplicate entries. In this tutorial, I’ll explain…

Escape Quotes from String in Python

As you must already know, quotes are used in Python to delimiter a string. In other words, quotes are interpreted by Python as the beginning or end of a string. Nevertheless, you can face a situation where your string actually…

Take a Float or Integer Input in Python

When you learn Python, one of the first operation you are asked to perform is to ask an input from the user, using the input() fonction. This function only takes one argument, which is the message displayed to the user,…

Find Common Elements in two Lists in Python

The lists [‘apple’,’banana’,’strawberry’] and [‘orange’,’banana’] have one comment element: ‘banana’. There are countless cases where we want to find common elements between two lists in Python. In this tutorial, we’ll explain the different options we have at our disposal to…

Remove duplicates from a list in Python

Lists are one of the most common data types in Python and are used to store data sequentially. We’ll often need to remove duplicates entries to ensure that we are handling a unique list of elements. In this tutorial, we’ll look…

Count the frequencies in a list in Python

When it comes to data analysis, one of the most common operations you can perform on a list is to count the item frequencies. This operation will return the unique values of your list and the number of times they…

Check if an Element is in a list in Python

Lists are one of the most common data types in Python and are used to store data sequentially. Even if you can add several times the same value, there are cases where you do not want to do that and…

List Files in a Directory in Python

Python provides an easy way to create and delete files & folders. In this tutorial, we will cover how to perform one of the most common task: list all files in a directory. To better understand our codes, we’ll assume…