Decimals -> Fraction strings, my solution
David C. Ullrich
ullrich at math.okstate.edu
Tue May 23 15:28:33 EDT 2000
More information about the Python-list mailing list
Tue May 23 15:28:33 EDT 2000
- Previous message (by thread): Decimals -> Fraction strings, my solution
- Next message (by thread): accesing socket at a lower level?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 22 May 2000 13:36:27 -0400, =?ISO-8859-1?Q?Fran=E7ois_Pinard?= <pinard at iro.umontreal.ca> wrote: >ullrich at math.okstate.edu (David C. Ullrich) writes: > >> def gcd(a, b): >> while a: >> a, b = b % a, a >> return b > >By the way, I think the above could be better written: > >def gcd(a, b): > while b: > a, b = b, a % b > return a > >It does not change much, and I'm not even sure exactly why, but I find it >more legible. I had no idea what you were getting at at all until you explained elsewhere that preserving a > b seemed more natural. (I think that allowing a call gcd(a,b) whether a > b or not is good - if a < b the first time through the loop will swap them - probably that initial "if a < b swap" might be faster. But I'm not gonna worry about that, cuz I use this in situations where there's no "<" in any case...) >-- >François Pinard http://www.iro.umontreal.ca/~pinard > > >
- Previous message (by thread): Decimals -> Fraction strings, my solution
- Next message (by thread): accesing socket at a lower level?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list