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 number

    Python, Math

    Converts a number to a list of digits.

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

  • Converts an integer to its roman numeral representation. Accepts value between 1 and 3999 (both inclusive).

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

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

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

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

  • Initializes a list containing the numbers in the specified range where start and end are inclusive and the ratio between two terms is step.

  • Median

    Python, Math

    Finds the median of a list of numbers.

  • N max elements

    Python, List

    Returns the n maximum elements from the provided list.

  • N min elements

    Python, List

    Returns the n minimum elements from the provided list.

  • Reverse number

    Python, Math

    Reverses a number.