On 2008-05-04 01:10:40 -0600, Arnaud Delobelle <[EMAIL PROTECTED]> said:

dave <[EMAIL PROTECTED]> writes:

Hello,

I made a function that takes a word list (one word per line, text
file) and searches for all the words in the list that are 'shifts' of
eachother.  'abc' shifted 1 is 'bcd'

Please take a look and tell me if this is a viable solution.

def shift(word, amt):
        ans = ''
        for letter in word:
                ans = ans + chr((ord(letter) - ord('a') + amt) % 26 + ord('a'))
        return ans

In Python, if you want to build a string from lots of parts you can
use ''.join(parts).  I think it is considered more efficient.


what would be the best way to write a "ans = ans + chr" into a ''.join(parts) ??


--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to