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

    Python, List

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

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

  • Writing short, efficient Python code is not always straightforward. Read how we optimize our list snippets to increase performance using a couple of simple tricks.

  • count_by

    Python, List

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

  • sort_by_indexes

    Python, List

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

  • bifurcate_by

    Python, List

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

  • group_by

    Python, List

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

  • unfold

    Python, Function

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

  • map_dictionary

    Python, List

    Maps the values of a list to a dictionary using a function, where the key-value pairs consist of the original value as the key and the result of the function as the value.

  • shuffle

    Python, List

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

  • difference_by

    Python, List

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

  • filter_non_unique

    Python, List

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

  • filter_unique

    Python, List

    Creates a list with the unique values filtered out.

  • get

    Python, Dictionary

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

  • intersection_by

    Python, List

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