Python Dictionary 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.

  • Invert dictionary

    Inverts a dictionary with non-unique hashable values.

    Python, Dictionary · Nov 2, 2020

  • Combine dictionary values

    Combines two or more dictionaries, creating a list of values for each key.

    Python, Dictionary · Apr 4, 2021

  • Group list elements

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

    Python, List · Nov 2, 2020

  • Sort dictionary by value

    Sorts the given dictionary by value.

    Python, Dictionary · Jan 7, 2021

  • 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

  • Map list to dictionary

    Maps the values of a list to a dictionary using a function.

    Python, List · Nov 2, 2020

  • Collection is empty

    Checks if the a value is an empty sequence or collection.

    Python, List · Jan 12, 2023

  • What are named tuples in Python?

    Understand Python's named tuples and start using them in your projects today.

    Python, List · Jun 12, 2021

  • Pluck values from list of dictionaries

    Converts a list of dictionaries into a list of values corresponding to the specified key.

    Python, List · Oct 22, 2020

  • Invert dictionary

    Inverts a dictionary with unique hashable values.

    Python, Dictionary · Nov 2, 2020

  • Merge dictionaries

    Merges two or more dictionaries.

    Python, Dictionary · Nov 2, 2020

  • Tip: Sort Python dictionary list using a tuple key

    Learn how to sort a Python dictionary list using a tuple key.

    Python, List · Jan 4, 2023

  • Sort dictionary by key

    Sorts the given dictionary by key.

    Python, Dictionary · Nov 2, 2020

  • Map dictionary values

    Creates a dictionary with the same keys as the provided dictionary and values generated by running the provided function for each value.

    Python, Dictionary · Nov 2, 2020

  • Find keys with value

    Finds all keys in the provided dictionary that have the given value.

    Python, Dictionary · Nov 2, 2020