Felipe
I get the same results as you. You make a good point about not
iterating when it's not needed. I played around with your test code
and found some interesting things:
1. enumerate vs. range(len()) has very little overhead (something I
have wondered about)
In my code, making the change c
Em Qua, 2006-03-29 às 22:20 -0800, Caleb Hattingh escreveu:
> That is very succint. Rewriting my shift function given earlier:
>
> >>> import string
> >>> alpha = string.ascii_lowercase
> >>> print alpha
> abcdefghijklmnopqrstuvwxyz
> >>> def shift(lst, n):
> return [lst[(i+len(lst)-n)%len(
Terry
That is very succint. Rewriting my shift function given earlier:
>>> import string
>>> alpha = string.ascii_lowercase
>>> print alpha
abcdefghijklmnopqrstuvwxyz
>>> def shift(lst, n):
return [lst[(i+len(lst)-n)%len(lst)] for i,item in enumerate(lst)]
>>> print shift(alpha,2)
['y',
"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 f
Em Qua, 2006-03-29 às 19:34 +, John Salerno escreveu:
> 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
Caleb Hattingh wrote:
> Also, I suspect you meant to say:
>
alphabet = string.ascii_lowercase
code = alphabet[2:] + alphabet[:2]
Ah yes, I see what you did there. :)
> I actually create a new list here, although since lists are mutable, I
> could probably just change items in-place.
John
In python, strings are immutable - you have to create a new string no
matter what you do.
Also, I suspect you meant to say:
>>> alphabet = string.ascii_lowercase
>>> code = alphabet[2:] + alphabet[:2]
I had a similar need recently for a guitar chord generator program I've
been working on.
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 = st
Ok, for those who have gotten as far as level 2 (don't laugh!), I have a
question. I did the translation as such:
import string
alphabet = string.lowercase[:26]
code = string.lowercase[2:26] + 'ab'
clue = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc
dmp. bmgle gr gl zw fyl