计算python中最大的共同点 [英] Computing greatest common denominator in python
本文介绍了计算python中最大的共同点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果你有一个python中的整数列表,比如说 L = [4,8,12,24]
,你如何计算它们最大的公分母/除数(在这种情况下为4)?
If you have a list of integers in python, say L = [4,8,12,24]
, how can you compute their greatest common denominator/divisor (4 in this case)?
推荐答案
一种方法是:
import fractions
def gcd(L):
return reduce(fractions.gcd, L)
print gcd([4,8,12,24])
这篇关于计算python中最大的共同点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文