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.

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

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

  • capitalize_every_word

    Python, String

    Capitalizes the first letter of every word in a string.

  • clamp_number

    Python, Math

    Clamps num within the inclusive range specified by the boundary values.

  • compact

    Python, List

    Removes falsy values from a list.

  • count_occurrences

    Python, List

    Counts the occurrences of a value in a list.

  • days_diff

    Python, Date

    Calculates the day difference between two dates.

  • degrees_to_rads

    Python, Math

    Converts an angle from degrees to radians.

  • difference

    Python, List

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

  • digitize

    Python, Math

    Converts a number to a list of digits.

  • drop

    Python, List

    Returns a list with n elements removed from the left.