Euclid's Algorithm in Python?

Jordan Rastrick jrastrick at
Mon Aug 8 02:31:02 CEST 2005

Good point. I suppose I'd only ever seen it implemented with the if
test, but you're right, the plain while loop should work fine. Silly

def gcd(a,b):
     while b != 0:
           a, b = b, a%b
    return a

Even nicer.

More information about the Python-list mailing list