GCD in standard library?
Skip Montanaro
skip at pobox.com
Wed Mar 12 20:20:58 EST 2003
Blake> I'm just guessing it is very common for people to have to add
Blake> this to their programs:
Blake> def gcd(x,y):
Blake> if x % y == 0: return y
Blake> else: return gcd(y,x%y)
Depends on what field you're in. I have been programming in Python for nine
or ten years and have never once had the need for a gcd function.
As for adding it to the math module, that goes against the typical grain of
Python's core extension modules. They generally expose functions in a
corresponding Unix C library. Since there's no gcd in the Unix math (-lm)
library, there's no gcd() in the math module.
Skip
More information about the Python-list
mailing list