Re: python challenge question (string manipulation)

2006-03-30 Thread Caleb Hattingh
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

Re: python challenge question (string manipulation)

2006-03-29 Thread Felipe Almeida Lessa
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(

Re: python challenge question (string manipulation)

2006-03-29 Thread Caleb Hattingh
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',

Re: python challenge question (string manipulation)

2006-03-29 Thread Terry Reedy
"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

Re: python challenge question (string manipulation)

2006-03-29 Thread Felipe Almeida Lessa
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

Re: python challenge question (string manipulation)

2006-03-29 Thread John Salerno
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.

Re: python challenge question (string manipulation)

2006-03-29 Thread Caleb Hattingh
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.

Re: python challenge question (string manipulation)

2006-03-29 Thread John Salerno
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

python challenge question (string manipulation)

2006-03-29 Thread John Salerno
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