-1
def gcd(x, y):
    (x, y) = (y, x) if x > y else (x, y)
    for factor in range(x, 0, -1):
        if x % factor == 0 and y % factor == 0:
            return factor

What is the use of the code:

(x, y) = (y, x) if x > y else (x, y)

Isn’t it enough to get the factor through the rest of the code? I have tried to get rid of the first line and the code went wrong, but I still can’t understand it.

Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
Kim Quek
  • 9
  • 2

1 Answers1

0

This insurances that the resulting x is always smaller then y.