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.

  1. Python - Create an empty list
  2. Python - Create a list of size n
  3. Python - Create a list of numbers from 1 to n
  4. Python - Create a list of strings
  5. Python - Create a list of objects
  6. 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.

  1. Python List - Access elements
  2. Python List - Get item at specific index
  3. Python List - Get first element
  4. Python List - Get last element
  5. Python List - Iterate with index
  6. Python List - Loop through items
  7. Python List - While loop
  8. Python List - For loop
  9. Python - Unpack List

List Properties

  1. Python - List length

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.

  1. Python - Add item to list
  2. Python - Remove specific item from list
  3. Python - Remove item at specific index from list
  4. Python - Remove all occurrences of an item from list
  5. Python - Remove duplicates from list
  6. Python - Append a list to another list
  7. Python - Reverse list
  8. Python - Sort list
  9. Python - Sort list in descending order
  10. Python - Shuffle list
  11. 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.

  1. Python - Check if list is empty
  2. Python - Check if element is present in list
  3. Python - Check if value is in list using "in" operator
  4. Python - Check if list contains all elements of another list
  5. 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.

  1. Python - Count the occurrences of items in a List with a specific value
  2. Python - Find duplicates in list
  3. Python - Find unique elements in list
  4. Python - Find index of specific item in list
  5. Python - Insert item at specific position in list
  6. Python - Find element with most number of occurrences in the list
  7. 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.

  1. Python List Comprehension
  2. Python List Comprehension with two lists
  3. Python List Comprehension with If condition
  4. Python List Comprehension with multiple conditions
  5. Python List Comprehension with List of Lists
  6. Python List Comprehension with nested For loops

List Filtering

These tutorials cover filtering operations on lists based on a condition or a function, etc.

  1. Python - Filter list
  2. Python - Filter list of strings that start with specific prefix string
  3. Python - Filter list based on datatype

Sub-Lists

These tutorials cover how to access sublists of a list.

  1. Python - Get list without last element
  2. Python - Traverse list except last element
  3. Python List - Get first N elements
  4. Python List - Get last N elements
  5. Python List - Slice
  6. Python List - Slice first N elements
  7. Python List - Slice last N elements
  8. Python List - Slice all but last
  9. 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.

  1. Python - Convert List to Dictionary
  2. Python - Convert dictionary keys to list
  3. Python - Convert dictionary values to list
  4. Python - Convert list to tuple
  5. Python - Convert tuple to list
  6. Python - Convert list to set
  7. Python - Convert set to list
  8. Python - Convert list to string
  9. Python - Convert CSV string to list
  10. Python - Convert list to CSV string
  11. Python - Convert numeric range to a list
  12. Python - Convert list of lists to a flat list

Converting List Elements

  1. Python - Convert list of strings into list of integers
  2. Python - Convert list of strings into list of floats
  3. Python - Convert list of integers into list of strings
  4. 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.

  1. Python - Find average of numbers in list
  2. Python - Find largest number in list
  3. Python - Find smallest number in list
  4. Python - Find sum of all numbers in numeric list
  5. Python - Find product of all numbers in numeric list
  6. Python - Sort numbers

String Lists

The following tutorials cover use-cases where all the elements of the list are strings.

  1. Python - Compare lists lexicographically
  2. Python - Find shortest string in list
  3. Python - Find longest string in list
  4. Python - Find most occurred string in a list
  5. Python - Find least occurred string in a list
  6. Python - Sort list of strings based on length
  7. 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.

  1. Python - Join list with new line
  2. Python - Join list with comma
  3. Python - Join list with space

Printing Lists

These tutorials cover different ways of printing a list in Python.

  1. Python - Print list
  2. Python - Print list without brackets
  3. Python - Print list without commas
  4. Python - Print list without quotes
  5. Python - Print list without spaces
  6. Python - Print list without brackets and commas
  7. Python - Print list without brackets and quotes
  8. Python - Print list without quotes and commas
  9. Python - Print list in reverse order
  10. Python - Print list in JSON format
  11. Python - Print list with double quotes
  12. Python - Print list with index
  13. Python - Print list as column
  14. Python - Print list as lines
  15. Python - Print elements at even indices in List
  16. 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.

  1. Python List ValueError: too many values to unpack
  2. Python List ValueError: not enough values to unpack

List Other Topics

  1. Python List of Lists
  2. Python List vs Set

Summary

In this tutorial of Python Examples, we learned about the usage and syntax of different List Operations in Python.




Python Libraries