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

  • Calculates the greatest common divisor of a list of numbers.

  • Returns the least common multiple of a list of numbers.

  • Powerset

    Python, Math

    Returns the powerset of a given iterable.

  • Weighted average

    Python, Math

    Returns the weighted average of two or more numbers.

  • Hamming distance

    Python, Math

    Calculates the Hamming distance between two values.

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

  • Returns the index of the element with the maximum value in a list.

  • Maps a number from one range to another range.

  • Returns the index of the element with the minimum value in a list.

  • Average

    Python, Math

    Calculates the average of two or more numbers.

  • Fibonacci

    Python, Math

    Generates a list, containing the Fibonacci sequence, up until the nth term.

  • Clamp number

    Python, Math

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

  • Number in range

    Python, Math

    Checks if the given number falls within the given range.

  • Number is prime

    Python, Math

    Checks if the provided integer is a prime number.

  • Pad number

    Python, String

    Pads a given number to the specified length.