Category list

How to Write a List to a CSV file in Python?

You can use the csv module, the Pandas library or even pure Python code to write a list to a CSV file. This operation will allow you to convert data from one of the most common data types in Python…

How to Check if a List is Empty in Python

Lists are one of the most common data types you’ll be using if you start coding with Python. One of the usual checks you may have to perform is to check if a list is empty. In this tutorial, we’ll…

Find the Median of a List in Python

When you work with numerical list in Python, you may need to apply aggregation like finding the average. Most common operations are built-in in Python and no extra-code is needed. That being said, there is no function or method to…

How to get the average of a list in Python?

If we look at the official documentation, we can realize that Python does not come with a native mean() or average() function, as it does with sum() or len(). Therefore, calculating the average of a list in Python is not…

How to Get the Last Element of a List in Python

Getting the last element of a list is often counter-intuitive, but is sometimes needed for a logic we want to implement in Python. In this tutorial, we’ll explain the different methods you can use to extract the last element from…

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…

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…