If you have a list of integers in python, let's say L = [4,8,12,24] , how can you calculate their greatest common denominator / divisor (in this case 4)?
L = [4,8,12,24]
One way to do this:
import fractions def gcd(L): return reduce(fractions.gcd, L) print gcd([4,8,12,24])
good, this will reduce the time complexity for a huge list (len> 10 ^ 9)