Skip to content

Python Tutorials

On this page, you’ll find a list of Python tutorials, broken down by their topics.

Python Lists

Python lists are mutable, heterogenous, and ordered data structures that are frequently used to store different types of data. In the tutorials below, you’ll learn a number of different helpful skills to be able to better understand, use, and manipulate Python lists. Lists are intuitive and approachable, making them an important skill to master.

Featured Python List Articles

The articles listed below are represent comprehensive guides to be able to better work with key features of Python lists.

List Comprehensions in Python (Complete Guide with Examples) allows you to understand a key feature of Python. Comprehensions represent a key way to loop over and manipulate lists, or to generate new lists in a readable and intuitive way.

Python List Tutorials

  • Python UserList – Custom Python Lists with collections
    Building custom lists allows you to define powerful programs, by extending on the functionality of normal Python lists. You can easily build new lists that have custom behavior or new functionalities, which build on top of regular Python lists. In this tutorial, you’ll learn how to use the Python collections UserList class to create custom lists. You’ll also learn how to build your own custom list, by building a list that allows only numbers and allows you to build custom methods that can square all values. By the end of this tutorial, you’ll have learned the following: How to build… Read More »Python UserList – Custom Python Lists with collections
  • How to Round to 2 Decimal Places in Python
    Being able to work with and round floating point values, or decimal values, in Python is an important skill. In this tutorial, you’ll learn how to round to decimal places in Python, including learning how to round up or down. You will also learn how to simply represent values with 2 decimal places, without changing the value itself. By the end of this tutorial, you’ll have learned: How to round to 2 decimal places in Python, including rounding up and down How to format values as currency in Python How to round lists and arrays of numbers to 2 decimal… Read More »How to Round to 2 Decimal Places in Python
  • Difference Between Array and List in Python
    In this post, you’ll learn the difference between arrays and lists in Python. Both these data structures let you store data in Python and share many similar properties. However, they also let you do quite different things and knowing when to use which can make you a much stronger programmer! In particular, you’ll learn how the Python list is different from both the array and the NumPy array. You’ll get a strong understanding of when to use either of these data structures. By the end of this tutorial, you’ll have learned: How Python lists and arrays are similar and how… Read More »Difference Between Array and List in Python
  • Python: Differences Between Lists and Tuples
    In this tutorial, you’ll learn the differences between Python lists and tuples. Lists and tuples are fundamental Python container data structures. On the surface, they seem very similar. However, there are a number of unique differences between them that makes their use cases quite clear. By the end of this tutorial, you’ll have learned: What the key differences and similarities are between Python Lists and Python Tuples When using a list is more appropriate than using a tuple When using a tuple is more appropriate than using a list What methods are and aren’t available for the two data structures… Read More »Python: Differences Between Lists and Tuples
  • How to Check if a Python List is Empty
    In this tutorial, you’ll learn how to use Python to check if a list empty. Python lists are one of the most versatile and widely-used container objects. Because Python lists are iterable, you may often want to first check if a list is empty, before attempting to iterate over a list. Without this, your program may run into issues and crash. By the end of this tutorial, you’ll have learned: How to use Python to check if a list is empty Why you would want to check if a Python list is empty How to check if a list of… Read More »How to Check if a Python List is Empty
  • How to Iterate (Loop) Over a List in Python
    In this tutorial, you’ll learn how to iterate (or loop) over a list in Python. You’ll learn how to iterate with for loops, while loops, comprehensions, and more. What’s more, is that you’ll learn when each of these methods is the best method to use. Given that there are many different ways of accomplishing this, it can be helpful to understand which method to use. Python lists are one of the cornerstone data structures in the language. They are ordered and indexable, meaning that their order matters and that you can access items based on their order. They’re also heterogeneous,… Read More »How to Iterate (Loop) Over a List in Python
  • Python map Function: Transforming Iterables without Loops
    In this tutorial, you’ll learn how to use the built-in Python map() function. This function allows you to process and transform, or “map”, items in an iterable without needing to use a loop to iterate. The function allows you to write incredibly readable code, which specifies the intention of what you’re doing. By the end of this tutorial, you’ll have learned: What the Python map() function is How the Python map() function is a good alternative to for loops and list comprehensions How to use the Python map() function with built-in functions, custom functions, and lambda functions How to use… Read More »Python map Function: Transforming Iterables without Loops
  • Python filter: A Complete Guide to Filtering Iterables
    The Python filter function is a built-in way of filtering an iterable, such as a list, tuple, or dictionary, to include only items that meet a condition. In this tutorial, you’ll learn how to use the filter() function to filter items that meet a condition. You’ll learn how to use the function to filter lists, tuples, and dictionaries. You’ll also learn how to streamline your filter functions with anonymous lambda functions. By the end of this tutorial, you’ll have learned: How the Python filter() function can be used to filter iterable objects, such as lists, tuples, dictionaries, and more How… Read More »Python filter: A Complete Guide to Filtering Iterables
  • Python List sort(): An In-Depth Guide to Sorting Lists
    In this tutorial, you’ll learn how to use Python to sort a list using the sort() method. Being able to work with lists is an essential skill in Python, given their prevalence. Because lists are ordered and mutable data structures, we can modify their order. The list.sort() method allows you to do exactly this! The method is a valuable method that allows you to sort in many custom ways. By the end of this tutorial, you’ll have learned: How to use the Python sort method to sort a list How to sort in ascending, descending and custom orders How to sort lists of lists, lists… Read More »Python List sort(): An In-Depth Guide to Sorting Lists
  • Python List Extend: Append Multiple Items to a List
    In this tutorial, you’ll learn how to use the Python list extend method, which lets you append multiple items to a list. The Python .extend() method is very similar to the Python .append() method, but lets you add multiple elements to a list at once. You’ll learn how to use the Python extend method to add a single item or multiple items to a list, including from other lists, tuples, and more. By the end of this tutorial, you’ll have learned: How the Python list extend method works How to add a single item or multiple items to a list… Read More »Python List Extend: Append Multiple Items to a List
  • Python: Find List Index of All Occurences of an Element
    In this tutorial, you’ll learn how to use Python to find the list index of all occurrences of an element. In many cases, Python makes it simple to find the first index of an element in a list. However, because Python lists can contain duplicate items, it can be helpful to find all of the indices of an element in a list. By the end of this tutorial, you’ll have learned: How to find the indices of all occurences of an element in a Python list using: For loops, List comprehensions, NumPy, and more_itertools Which method is fastest Let’s get… Read More »Python: Find List Index of All Occurences of an Element
  • Convert a List of Dictionaries to a Pandas DataFrame
    In this tutorial, you’ll learn how to convert a list of Python dictionaries into a Pandas DataFrame. Pandas provides a number of different ways in which to convert dictionaries into a DataFrame. You’ll learn how to use the Pandas from_dict method, the DataFrame constructor, and the json_normalize function. By the end of this tutorial, you’ll have learned: How to convert a list of dictionaries to a Pandas DataFrame How to work with different sets of columns across dictionaries How to set an index when converting a list of dictionaries to a DataFrame How to convert nested dictionaries to a Pandas… Read More »Convert a List of Dictionaries to a Pandas DataFrame
  • Generate Random Numbers in Python
    In this tutorial, you’ll learn how to generate random numbers in Python. Being able to generate random numbers in different ways can be an incredibly useful tool in many different domains. Python makes it very easy to generate random numbers in many different ways. In order to do this, you’ll learn about the random and numpy modules, including the randrange, randint, random, and seed functions. You’ll also learn about the uniform and normal functions in order to create more controlled random values. By the end of this tutorial, you’ll have learned: How to generate random floating point values and integers… Read More »Generate Random Numbers in Python
  • Python List Index: Find First, Last or All Occurrences
    In this tutorial, you’ll learn how to use the Python list index method to find the index (or indices) of an item in a list. The method replicates the behavior of the indexOf() method in many other languages, such as JavaScript. Being able to work with Python lists is an important skill for a Pythonista of any skill level. We’ll cover how to find a single item, multiple items, and items meetings a single condition. By the end of this tutorial, you’ll have learned: How the Python list.index() method works How to find a single item’s index in a list… Read More »Python List Index: Find First, Last or All Occurrences
  • Prepend to a Python a List (Append at beginning)
    In this tutorial, you’ll learn how to use Python to prepend a list. While Python has a method to append values to the end of a list, there is no prepend method. By the end of this tutorial, you’ll have learned how to use the .insert() method and how to concatenate two lists to prepend. You’ll also learn how to use the deque object to insert values at the front of a list. In many cases, this is the preferred method, as it’s significantly more memory efficient than other methods. The Problem with Prepending a Python List Python lists are… Read More »Prepend to a Python a List (Append at beginning)
  • Find Duplicates in a Python List
    In this tutorial, you’ll learn how to find and work with duplicates in a Python list. Being able to work efficiently with Python lists is an important skill, given how widely used lists are. Because Python lists allow us to store duplicate values, being able to identify, remove, and understand duplicate values is a useful skill to master. By the end of this tutorial, you’ll have learned how to: Find duplicates in a list, as well as how to count them Remove duplicates in Python lists Find duplicates in a list of dictionaries and lists Let’s get started! How to… Read More »Find Duplicates in a Python List
  • Python: Multiply Lists (6 Different Ways)
    Learn how to use Python to multiply lists, including multiplying lists by a number and multiplying lists element-wise using numpy.
  • Python Lists: A Complete Overview
    In this tutorial, you’ll learn all you need to know to get started with Python lists. You’ll learn what lists are and how they can be used to store data. You’ll also learn how to access data from within lists by slicing and indexing data. You’ll learn how to add data to lists and as well as how to delete items. You’ll also learn how to create lists of lists, which can often be used to represent matrices of data. What are Python Lists Python lists are a data collection type, meaning that we can use them as containers for… Read More »Python Lists: A Complete Overview
  • Python: Select Random Element from a List
    Learn how to use Python to choose a random list element, with and without replacement and how to replicate results with a random seed.
  • 4 Ways to Clear a Python List
    Learn how to use Python to clear a list, using clear, del, and indexing methods, as well as some general attributes about Python lists.
  • Python IndexError: List Index Out of Range Error Explained
    Learn how to resolve the Python IndexError, list index out of range, why it occurs in for loops, while loops, and how to resolve it.
  • Python: Get Index of Max Item in List
    Learn how to use Python to get the index of the max item in a list, including when duplicates exist, using for loops, enumerate, and numpy.
  • Python: Combine Lists – Merge Lists (8 Ways)
    Learn how to combine Python lists and how to merge lists, including in alternating sequence and with unique or common elements.
  • Python: Check if List Contains an Item
    Learn how to check if a Python list contains an element using different methods, including the in keyword, the count method, and more!
  • Remove an Item from a Python List (pop, remove, del, clear)
    Learn how to remove an item from a Python list, using the pop, remove, and del methods. Also learn how to clear an entire list.
  • How to Reverse a Python List (6 Ways)
    Learn how to use Python to reverse a list, including how to use the reversed function, list indexing, and a python list comprehension.
  • Python: Replace Item in List (6 Different Ways)
    Learn how to replace an item or items in a Python list, including how to replace at an index, replacing values, replacing multiple values.
  • Python: Remove Duplicates From a List (7 Ways)
    Learn how to use Python to remove duplicates from a list, including how to maintain order from the original list, using seven methods.
  • Python Absolute Value: Abs() in Python
    Learn how to calculate a Python absolute value using the abs() function, as well as how to calculate in numpy array and a pandas dataframe.
  • Python: Convert a Dictionary to a List of Tuples (4 Easy Ways)
    Learn how to use Python to convert a dictionary into a list of tuples, using list comprehensions, the zip function, and collections.
  • Python: Shuffle a List (Randomize Python List Elements)
    Learn how to use Python to shuffle a list, including being able to reproduce a given result and shuffling Python lists of lists.
  • Python: Intersection Between Two Lists
    Learn how to find the intersection between two lists in Python, including using list comprehensions, set methods and the numpy library.
  • Python: Subtract Two Lists (4 Easy Ways!)
    Learn how to use Python to subtract two lists, using the numpy library, the zip function, for-loops, as well as list comprehensions.
  • Python List Length or Size: 5 Ways to Get Length of List
    Learn how to use Python to find the length of a list, including using the built-in len() function, and findings lengths of lists of lists.
  • Python: Transpose a List of Lists (5 Easy Ways!)
    Learn how to use Python to transpose a list of lists using numpy, itertools, for loops, and list comprehensions in this tutorial!
  • Pandas: Create a Dataframe from Lists (5 Ways!)
    Learn how to create a Pandas dataframe from lists, including using lists of lists, the zip() function, and ways to add columns and an index.
  • Python: Split a List (In Half, in Chunks)
    Learn how to split a Python list into n chunks, including how to split a list into different sized sublists or a different number of sublists.
  • Python: Combinations of a List (Get All Combinations of a List)
    Learn how to get all combinations of a Python list, including with substitution, using the helpful itertools library.
  • Python: Flatten Lists of Lists (4 Ways)
    Learn how to use Python to flatten a list of lists, including using the itertools library, list comprehension, and multi-level lists of lists.
  • How to Append to Lists in Python – 4 Easy Methods!
    Learn all the ways to append to lists in Python, including using the append, insert, and extend methods as well as how to concatenate lists!
  • List Comprehensions in Python (Complete Guide with Examples)
    List Comprehensions provide easy and concise ways to generate lists in Python. Learn how to write list comprehensions in Python using this tutorial.
  • 6 Ways to Convert a Python List to a String
    In this tutorial, you’ll learn how to use Python to convert (or join) a list to a string. Using Python to convert a list to a string is a very common task you’ll encounter. There are many different ways in which you can tackle this problem and you’ll learn the pros and cons of each of these approaches. By the end of this tutorial, you’ll have learned: How to use the .join() method to convert a Python list to a string How to use the map() function to convert a Python list to a string How to work with heterogenous… Read More »6 Ways to Convert a Python List to a String

Python Dictionaries

Python dictionaries are a built-in data type that uses a key:value pair to store data. In other languages, similar data structures are known as associative arrays. They are ordered, changeable, and require keys to be unique.

Featured Python Dictionary Articles

Python Dictionary Comprehensions (With Examples) – learn all you need to know about how Python Dictionary Comprehensions work. Comprehensions represent a Pythonic way to generate new dictionaries, by iterating over different items and manipulating either (or both) the key or values of an array.

Python Dictionary Tutorials

Python Strings

Python strings are surrounded by single, double, or triple quotes and are immutable (meaning they need to be reassigned to be altered), are ordered (meaning they can be indexed) and are incredibly common ways to hold information. Because of this, knowing how to work with strings is an important skill for any Pythonista. The tutorials below will teach you common ways to work with strings, often describing many different ways to fit your own personal programming style!