Start of main content## 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.

### Greatest common divisor

Python, Math

Calculates the greatest common divisor of a list of numbers.

### Least common multiple

Python, Math

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.

### Arithmetic progression

Python, Math

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

### Index of max element

Python, Math

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

### Map number to range

Python, Math

Maps a number from one range to another range.

### Index of min element

Python, Math

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.