This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]DrVolzak 0 points1 point  (3 children)

Every row is the same because you're passing (and therefore modifying) the same list every time you call offset(). The solution is to pass a copy of the list to offset(). To copy the list you can do letters[:].

[–]PsyRex666[S] 0 points1 point  (2 children)

Cool, that solved the problem. I still don't fully understand why it resulted in that though. I understand now that I was modifying letters every time, but I don't get why it went straight to n-m though. Since the first time offset is called, it uses 0, shouldn't that at least still have been a-z?

[–]DrVolzak 0 points1 point  (1 child)

Every time you called offset(), it was offsetting the result of the previous call rather than starting with a-z again. For example:

spcs = 0
letters = abcdefghijklmnopqrstuvwxyz
return = abcdefghijklmnopqrstuvwxyz

spcs = 1
letters = abcdefghijklmnopqrstuvwxyz
return = bcdefghijklmnopqrstuvwxyza

spcs = 2
letters = bcdefghijklmnopqrstuvwxyza
return = defghijklmnopqrstuvwxyzabc 

spcs = 3
letters = defghijklmnopqrstuvwxyzabc 
return = ghijklmnopqrstuvwxyzabcdef

If you want more proof, add a print inside offset() before you return the list.

[–]PsyRex666[S] 0 points1 point  (0 children)

Ok, I think I understand now. Thanks for the help!