Remove duplicate letters in a word

DavidW Blaschke dwblas at yahoo.com
Sun Jun 22 13:59:44 EDT 2003


A simple way is to sort the individual letters first.
You can put them in a list and use list.sort() or
whatever you prefer.  Then check each item with the
previous or next.  Note that if you use a for loop,
then you want to compare this item with the next item
and delete this item if it is a dup, for items from 0
to len-1, otherwise you will not test either the first
item in the list or the last.  Also convert to upper
or lower if case does not matter.  Do some testing and
you will see what I mean.

> --- In python-list at yahoogroups.com, Eliran Gonen
> <eg at r...> wrote:
> > Hello !
> > 
> > I'm new in this list.
> > 
> > Anyway, I'm trying to write some sort of
> encryption program (pretty
> > trivial and simple) that need to check for several
> occurences of a 
> letter
> > in a specific word.
> > 
> > For example, in the word SECRET, E appears twice,
> I need to get rid 
> of
> > the second instance of E.
> > 
> > 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,
> > 
> > TIA, EG
> > 
> > -- 
> >
> http://mail.python.org/mailman/listinfo/python-list
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com





More information about the Python-list mailing list