Python List Operations
Python List Operations
The following tutorials cover different operations on Lists like creation of lists, transformations on lists, update to lists, etc.
Create Lists in Python
In the following, you shall learn how to create lists in Python, like creating empty lists, creating list of specific data types, creating list of specify size, etc.
- Python - Create an empty list
- Python - Create a list of size n
- Python - Create a list of numbers from 1 to n
- Python - Create a list of strings
- Python - Create a list of objects
- Python - Create a list of empty lists
Access Lists
The following tutorials cover how you could access items in a list in different ways, like accessing items in a list using index, accessing first or last item, etc.
- Python List - Access elements
- Python List - Get item at specific index
- Python List - Get first element
- Python List - Get last element
- Python List - Iterate with index
- Python List - Loop through items
- Python List - While loop
- Python List - For loop
- Python - Unpack List
List Properties
Update / Transform Lists
The following tutorials cover scenarios on how you could modify or transform a list like sorting operations, removing items from list, adding items to list, etc.
- Python - Add item to list
- Python - Remove specific item from list
- Python - Remove item at specific index from list
- Python - Remove all occurrences of an item from list
- Python - Remove duplicates from list
- Python - Append a list to another list
- Python - Reverse list
- Python - Sort list
- Python - Sort list in descending order
- Python - Shuffle list
- Python - Covert list into list of lists
Checking Operations on Lists
The following tutorials cover scenarios on how you could make different types of checks on a list, or list items.
- Python - Check if list is empty
- Python - Check if element is present in list
- Python - Check if value is in list using "in" operator
- Python - Check if list contains all elements of another list
- Python - Check it lists are equal
List Finding Operations
In the following tutorial, you will learn how to search for an element, or find the index of a specific element, etc.
- Python - Count the occurrences of items in a List with a specific value
- Python - Find duplicates in list
- Python - Find unique elements in list
- Python - Find index of specific item in list
- Python - Insert item at specific position in list
- Python - Find element with most number of occurrences in the list
- Python - Find element with least number of occurrences in the list
List Comprehension Operations
These tutorials cover list comprehension, and special cases in a list comprehension.
- Python List Comprehension
- Python List Comprehension with two lists
- Python List Comprehension with If condition
- Python List Comprehension with multiple conditions
- Python List Comprehension with List of Lists
- Python List Comprehension with nested For loops
List Filtering
These tutorials cover filtering operations on lists based on a condition or a function, etc.
- Python - Filter list
- Python - Filter list of strings that start with specific prefix string
- Python - Filter list based on datatype
Sub-Lists
These tutorials cover how to access sublists of a list.
- Python - Get list without last element
- Python - Traverse list except last element
- Python List - Get first N elements
- Python List - Get last N elements
- Python List - Slice
- Python List - Slice first N elements
- Python List - Slice last N elements
- Python List - Slice all but last
- Python List - Slice reverse
List Conversions to/from other types
These tutorials cover conversions between list and other types like tuple, set, dictionary, string, etc.
- Python - Convert List to Dictionary
- Python - Convert dictionary keys to list
- Python - Convert dictionary values to list
- Python - Convert list to tuple
- Python - Convert tuple to list
- Python - Convert list to set
- Python - Convert set to list
- Python - Convert list to string
- Python - Convert CSV string to list
- Python - Convert list to CSV string
- Python - Convert numeric range to a list
- Python - Convert list of lists to a flat list
Converting List Elements
- Python - Convert list of strings into list of integers
- Python - Convert list of strings into list of floats
- Python - Convert list of integers into list of strings
- Python - Convert list of floats into list of strings
Numeric Lists
The following tutorials cover use-cases where all the elements of the list are numbers.
- Python - Find average of numbers in list
- Python - Find largest number in list
- Python - Find smallest number in list
- Python - Find sum of all numbers in numeric list
- Python - Find product of all numbers in numeric list
- Python - Sort numbers
String Lists
The following tutorials cover use-cases where all the elements of the list are strings.
- Python - Compare lists lexicographically
- Python - Find shortest string in list
- Python - Find longest string in list
- Python - Find most occurred string in a list
- Python - Find least occurred string in a list
- Python - Sort list of strings based on length
- Python - Sort a list alphabetically
Join Lists
The following tutorials cover use-cases where the elements of a list are joined by a specific delimiter or separator, to create a string.
Printing Lists
These tutorials cover different ways of printing a list in Python.
- Python - Print list
- Python - Print list without brackets
- Python - Print list without commas
- Python - Print list without quotes
- Python - Print list without spaces
- Python - Print list without brackets and commas
- Python - Print list without brackets and quotes
- Python - Print list without quotes and commas
- Python - Print list in reverse order
- Python - Print list in JSON format
- Python - Print list with double quotes
- Python - Print list with index
- Python - Print list as column
- Python - Print list as lines
- Python - Print elements at even indices in List
- Python - Print elements at odd indices in List
Exceptions with Lists
These tutorials cover some of the most encountered exceptions while working with lists in Python.
- Python List ValueError: too many values to unpack
- Python List ValueError: not enough values to unpack
List Other Topics
Summary
In this tutorial of Python Examples, we learned about the usage and syntax of different List Operations in Python.