word shifts
dave
squareswallower at yahoo.com
Mon May 5 23:02:06 EDT 2008
On 2008-05-04 01:10:40 -0600, Arnaud Delobelle <arnodel at googlemail.com> said:
> dave <squareswallower at invalid.com> 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) ??
More information about the Python-list
mailing list