Remove duplicate letters in a word

Bryan belred1 at yahoo.com
Sun Jun 22 13:40:57 EDT 2003


"Paul Rubin" <http://phr.cx@NOSPAM.invalid> wrote in message
news:7x4r2iowhw.fsf at ruckus.brouhaha.com...
> Eliran Gonen <eg at rootshell.be> writes:
> > I'm stuck here:
> >
> >     for i in range(len(key)):
> >         for j in range(len(key)):
> >             if key[i] == key[j] :
> >                 key[j] = ""
> >
> > Hope you can help me,
>
> You can't change the contents of a string in Python.  You have to
> make a new string:
>
>     temp = []
>     for c in key:
>       if c not in key2:
>          temp.append(c)
>     key = str(temp)


did you mean??

key = ''.join(temp)








More information about the Python-list mailing list