开发者

Computing greatest common denominator in python

开发者 https://www.devze.com 2023-01-15 07:06 出处:网络
If you have a list of integers in python, say L = [4,8,12,24], how can you compute their greatest common denomina开发者_高级运维tor/divisor (4 in this case)?One way to do it is:

If you have a list of integers in python, say L = [4,8,12,24], how can you compute their greatest common denomina开发者_高级运维tor/divisor (4 in this case)?


One way to do it is:

import fractions

def gcd(L):
    return reduce(fractions.gcd, L)

print gcd([4,8,12,24])
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号