Python List Snippets

The Python snippet collection contains helper functions for Python 3.6. It includes utilities for most common data types, such as primitivies, lists, dictionaries and date objects.

  • Merge lists

    Merges two or more lists into a list of lists, combining elements from each of the input lists based on their positions.

    Python, List · Nov 2, 2020

  • What is the difference between list.sort() and sorted() in Python?

    Learn the difference between Python's built-in list sorting methods and when one is preferred over the other.

    Python, List · Jun 12, 2021

  • Code Anatomy - Writing high performance Python code

    Writing efficient Python code can be tricky. Read how we optimize our list snippets to increase performance using a couple of simple tricks.

    Python, List · Nov 7, 2021

  • How can I check if a Python list is empty?

    There's a good way to test the emptiness of a Python list and a better one. Which one are you using?

    Python, List · Jan 15, 2023

  • Sort list by indexes

    Sorts one list based on another list containing the desired indexes.

    Python, List · Nov 2, 2020

  • Count grouped elements

    Groups the elements of a list based on the given function and returns the count of elements in each group.

    Python, List · Nov 2, 2020

  • Filter non-unique list values

    Creates a list with the non-unique values filtered out.

    Python, List · Nov 2, 2020

  • Filter unique list values

    Creates a list with the unique values filtered out.

    Python, List · Nov 2, 2020

  • Group list elements

    Groups the elements of a list based on the given function.

    Python, List · Nov 2, 2020

  • Unfold list

    Builds a list, using an iterator function and an initial seed value.

    Python, Function · Nov 2, 2020

  • Bifurcate list based on function

    Splits values into two groups, based on the result of the given filtering function.

    Python, List · Nov 2, 2020

  • Shuffle list

    Randomizes the order of the values of an list, returning a new list.

    Python, List · Nov 2, 2020

  • List difference based on function

    Returns the difference between two lists, after applying the provided function to each list element of both.

    Python, List · Nov 2, 2020

  • Get nested value

    Retrieves the value of the nested key indicated by the given selector list from a dictionary or list.

    Python, Dictionary · Oct 28, 2020

  • List intersection based on function

    Returns a list of elements that exist in both lists, after applying the provided function to each list element of both.

    Python, List · Nov 2, 2020