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

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

    Python, String · Sep 15, 2020

  • Digitize number

    Converts a number to a list of digits.

    Python, Math · Sep 15, 2020

  • Find parity outliers

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

    Python, List · Nov 2, 2020

  • Sum of powers

    Returns the sum of the powers of all the numbers from start to end (both inclusive).

    Python, Math · Nov 2, 2020

  • Integer to roman numeral

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

    Python, Math · Nov 2, 2020

  • RGB to hex

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

    Python, String · Nov 2, 2020

  • Mapped list average

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

    Python, Math · Nov 2, 2020

  • Geometric progression

    Initializes a list containing the numbers in the specified geometric progression range.

    Python, Math · Nov 2, 2020

  • Max list value based on function

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

    Python, Math · Nov 2, 2020

  • Median

    Finds the median of a list of numbers.

    Python, Math · Nov 2, 2020

  • Min list value based on function

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

    Python, Math · Nov 2, 2020

  • Sum list based on function

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

    Python, Math · Nov 2, 2020

  • N max elements

    Returns the n maximum elements from the provided list.

    Python, List · Nov 2, 2020

  • N min elements

    Returns the n minimum elements from the provided list.

    Python, List · Nov 2, 2020

  • Prime factors of number

    Finds and returns the list of prime factors of a number.

    Python, Math · May 24, 2023