"John Salerno" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > John Salerno wrote: > >> It works, but is there a better way to shift the letters of the alphabet >> for 'code'? I remember a method that did this for lists, I think, but I >> can't remember what it was or if it worked for strings. > > Ah ha! This is cleaner: > > alphabet = string.ascii_lowercase > code = string.ascii_lowercase[2:] + string.ascii_lowercase[:2] > > Yet it still seems kind of verbose. But since that's the official > solution, I guess there's no other way to shift the characters in a > string?
The above would look less verbose if the second line 'paid attention' to the first and were written as the slightly more efficient code = alphabet[2:] + alphabet[:2] An alternative is shifted access. alphabet[(i+24)%26] Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list