[Tutor] Re: rotating a list

Andrei project5 at redrival.net
Sat Sep 20 16:33:33 EDT 2003


Bob Gailer wrote:
>> Here's your problem your rotate x and assign the result to y:
>>
>>>         y = rotate(x)
>>
>>
>> Now x is unchanged, y is the result, so you go back and rotate the 
>> same old x again. Obviously the result won't change.
>>
>>>         print y
> 
> 
> No that is NOT the problem. That is an alternative algorithm. I 
> explained the problem in my post.

As far as I can tell, that's a matter of taste: the algorithm is exactly the 
same and the result is the same: he uses the default value of n=1 in this case 
to test his rotation which is just fine. One can either increment n in the loop 
or reassign x every time. Personally, I find reassigning more intuitive and I 
pretty much ignored the optional n parameter. Could you explain why incrementing 
n is a superior solution?

-- 
Yours,

Andrei

=====
Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5 at bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq gur 
yvfg, fb gurer'f ab arrq gb PP.





More information about the Tutor mailing list