String manipulation in python..NEED HELP!!!!

Terry Reedy tjreedy at udel.edu
Tue Dec 11 14:30:23 EST 2012


On 12/10/2012 5:59 PM, John Gordon wrote:

> def encode(plain):
>     '''Return a substituted version of the plain text.'''
>     encoded = ''
>     for ch in plain:
>        encoded += key[alpha.index(ch)]
>     return encoded

The turns an O(n) problem into a slow O(n*n) solution. Much better to 
build a list of chars and then join them.

-- 
Terry Jan Reedy




More information about the Python-list mailing list