Remove duplicate letters in a word

Paul Rubin http
Sun Jun 22 13:25:15 EDT 2003


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)




More information about the Python-list mailing list