Problems with string and lists (searching and replaceing)

Ulrich Petri ulope at
Mon Sep 22 11:30:07 CEST 2003

"Colin Fox" <cfox at> schrieb im Newsbeitrag
news:pan.2003. at
> Here's an alternative. I took out the 'if lg in word' logic,
> since that doesn't take into account duplicates and therefore
> would be misleading (ie 'jaguar','jaaaaa' would return 'x.....',
> but there aren't 5 a's in the word).
> #!/usr/bin/env python
> import string
> def wordcheck(word, guess):
>     outstr = []
>     if len(word) != len(guess):
>         raise "Wrong number of letters in guess."
>     for x in range(len(word)):
>         outstr.append( ['-','*'][(word[x]==guess[x])] )
>     return string.join(outstr,'')
> res = wordcheck('Colin','Coolo')
> print res

Yeah your right, but with your code there is no indication of a right letter
in the wrong position.
I guess one has to use a decorate-undecorate thing...
If i have some time later today i will test this...

Ciao Ulrich

More information about the Python-list mailing list