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.

  • Reverse number

    Reverses a number.

    Python, Math · Nov 2, 2020

  • Greatest common divisor

    Calculates the greatest common divisor of a list of numbers.

    Python, Math · Sep 15, 2020

  • Least common multiple

    Returns the least common multiple of a list of numbers.

    Python, Math · Nov 2, 2020

  • Powerset

    Returns the powerset of a given iterable.

    Python, Math · Nov 2, 2020

  • Weighted average

    Returns the weighted average of two or more numbers.

    Python, Math · Dec 24, 2020

  • Hamming distance

    Calculates the Hamming distance between two values.

    Python, Math · Feb 18, 2021

  • Arithmetic progression

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

    Python, Math · Nov 2, 2020

  • Index of max element

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

    Python, Math · Nov 2, 2020

  • Map number to range

    Maps a number from one range to another range.

    Python, Math · Apr 5, 2021

  • Index of min element

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

    Python, Math · Nov 2, 2020

  • Average

    Calculates the average of two or more numbers.

    Python, Math · Nov 2, 2020

  • Fibonacci

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

    Python, Math · Nov 2, 2020

  • Clamp number

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

    Python, Math · Nov 2, 2020

  • Number in range

    Checks if the given number falls within the given range.

    Python, Math · Sep 15, 2020

  • Number is prime

    Checks if the provided integer is a prime number.

    Python, Math · Nov 2, 2020