[Tutor] elegant way to turn list into string
Chris Smith
smichr at bigfoot.com
Sun May 8 01:06:00 CEST 2005
> while x < 26:
> new_alph = alph[1:] + alph[:1]
> print new_alph
> print "\n"
> x += 1
>
> But this has the drawback of not progressing with my
> newly create alphabet, it just returns:
> abcdefghijklmnopqrstuvwxyz
The reason that new_alph never changes is that you are calculating it
from the same (unchanging) thing every time. The value of alph never
changes in your loop, so the value of new_alph is always the same.
Others have given suggestions as to what else you might do, but a fix
for the above loop is to replace the word new_alph with alph.
/c
More information about the Tutor
mailing list