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.

  • Learn 3 easy ways to swap the values of two variables in Python.

  • add_days

    Python, Date

    Calculates the date of n days from the given date.

  • all_equal

    Python, List

    Checks if all elements in a list are equal.

  • all_unique

    Python, List

    Checks if all the values in a list are unique.

  • Generates a list of numbers in the arithmetic progression starting with the given positive integer and up to the specified limit.

  • average

    Python, Math

    Calculates the average of two or more numbers.

  • average_by

    Python, Math

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

  • bifurcate

    Python, List

    Splits values into two groups, based on the result of the given filter list.

  • bifurcate_by

    Python, List

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

  • Calculates the number of ways to choose k items from n items without repetition and without order.

  • byte_size

    Python, String

    Returns the length of a string in bytes.

  • camel

    Python, String

    Converts a string to camelcase.

  • capitalize

    Python, String

    Capitalizes the first letter of a string.

  • capitalize_every_word

    Python, String

    Capitalizes the first letter of every word in a string.

  • cast_list

    Python, List

    Casts the provided value as a list if it's not one.