开发者

Computing greatest common denominator in python

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜