Start of main content
Least common multiple
Python, Math, List · Nov 2, 2020

Returns the least common multiple of a list of numbers.
- Use
functools.reduce()
, math.gcd()
and lcm(x, y) = x * y / gcd(x, y)
over the given list.
from functools import reduce
from math import gcd
def lcm(numbers):
return reduce((lambda x, y: int(x * y / gcd(x, y))), numbers)
lcm([12, 7])
lcm([1, 3, 4, 5])
More like this

A snippet collection of list helpers and tips for Python 3.6.
Collection · 100 snippets

Calculates the greatest common divisor of a list of numbers.
Python, Math · Sep 15, 2020

Converts a number to a list of digits.
Python, Math · Sep 15, 2020

Initializes a list containing the numbers in the specified geometric progression range.
Python, Math · Nov 2, 2020