Short code snippets for all your development needs

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.

### hex_to_rgb

Python, String

Converts a hexadecimal color code to a tuple of integers corresponding to its RGB components.

### digitize

Python, Math

Converts a number to a list of digits.

### find_parity_outliers

Python, List

Finds the items that are parity outliers in a given list.

### rgb_to_hex

Python, String

Converts the values of RGB components to a hexadecimal color code.

### sum_of_powers

Python, Math

Returns the sum of the powers of all the numbers from

`start`

to`end`

(both inclusive).### to_roman_numeral

Python, Math

Converts an integer to its roman numeral representation. Accepts value between

`1`

and`3999`

(both inclusive).### average_by

Python, Math

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

### geometric_progression

Python, Math

Initializes a list containing the numbers in the specified range where

`start`

and`end`

are inclusive and the ratio between two terms is`step`

. Returns an error if`step`

equals`1`

.### max_by

Python, Math

Returns the maximum value of a list, after mapping each element to a value using the provided function.

### min_by

Python, Math

Returns the minimum value of a list, after mapping each element to a value using the provided function.

### sum_by

Python, Math

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

### median

Python, Math

Finds the median of a list of numbers.

### reverse_number

Python, Math

Reverses a number.

### lcm

Python, Math

Returns the least common multiple of a list of numbers.

### max_n

Python, List

Returns the

`n`

maximum elements from the provided list.