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

  • Tip: 2 ways to format a string in Python

    Learn two ways to format a string in Python with this quick tip.

    Python, String · Jun 12, 2021

  • List difference

    Calculates the difference between two iterables, without filtering duplicate values.

    Python, List · Nov 2, 2020

  • Value frequencies

    Creates a dictionary with the unique values of a list as keys and their frequencies as the values.

    Python, List · Nov 2, 2020

  • Collection is empty

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

    Python, List · Jan 12, 2023

  • Kebabcase string

    Converts a string to kebab case.

    Python, String · Nov 2, 2020

  • List symmetric difference

    Returns the symmetric difference between two iterables, without filtering out duplicate values.

    Python, List · Nov 2, 2020

  • Mapped list average

    Calculates the average of a list, after mapping each element to a value using the provided function.

    Python, Math · Nov 2, 2020

  • Geometric progression

    Initializes a list containing the numbers in the specified range where start and end are inclusive and the ratio between two terms is step.

    Python, Math · Nov 2, 2020

  • Longest item

    Takes any number of iterable objects or objects with a length property and returns the longest one.

    Python, List · Oct 17, 2021

  • 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

  • Max list value based on function

    Returns the maximum value of a list, after mapping each element to a value using the provided function.

    Python, Math · Nov 2, 2020

  • Median

    Finds the median of a list of numbers.

    Python, Math · Nov 2, 2020

  • Min list value based on function

    Returns the minimum value of a list, after mapping each element to a value using the provided function.

    Python, Math · Nov 2, 2020

  • Split into lines

    Splits a multiline string into a list of lines.

    Python, String · Nov 2, 2020