Problems with string and lists (searching and replaceing)
Ulrich Petri
ulope at gmx.de
Mon Sep 22 05:30:07 EDT 2003
"Colin Fox" <cfox at cfconsulting.ca> schrieb im Newsbeitrag
news:pan.2003.09.21.21.08.04.529981 at cfconsulting.ca...
> 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