Skip to content

Home

Greatest common divisor

Calculates the greatest common divisor of a list of numbers.

from functools import reduce
from math import gcd as _gcd

def gcd(numbers):
  return reduce(_gcd, numbers)

gcd([8, 36, 28]) # 4

More like this

Start typing a keyphrase to see matching snippets.