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

  • String to words

    Converts a given string into a list of words.

    Python, String · 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

  • Sort dictionary by value

    Sorts the given dictionary by value.

    Python, Dictionary · Jan 7, 2021

  • Camelcase string

    Converts a string to camelcase.

    Python, String · 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

  • Map list to dictionary

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

    Python, List · Nov 2, 2020

  • List symmetric difference based on function

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

    Python, List · Nov 2, 2020

  • List union based on function

    Returns every element that exists in any of the two lists once, after applying the provided function to each element of both.

    Python, List · Nov 2, 2020

  • Digitize number

    Converts a number to a list of digits.

    Python, Math · Sep 15, 2020

  • Collection is empty

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

    Python, List · Jan 12, 2023

  • Tip: Watch out for mutable default arguments in Python

    Mutable default arguments can trip up Python beginners and veterans alike. Here's a quick workaround to deal with them.

    Python, Function · Feb 27, 2022

  • What are named tuples in Python?

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

    Python, List · Jun 12, 2021