30 seconds of python

  Back to Home

gcd

mathbeginner

Calculates the greatest common divisor of a list of numbers.

Use reduce() and math.gcd over the given list.

from functools import reduce
import math

def gcd(numbers):
  return reduce(math.gcd, numbers)