Problems with string and lists (searching and replaceing)
jblazi
jblazi at hotmail.com
Sun Sep 21 15:59:29 EDT 2003
On Sun, 21 Sep 2003 20:40:30 +0200, Ulrich Petri wrote:
> def mastermind(word, guess):
> if len(word) != len(guess):
> return "Error"
> ret = ["-"]*len(word)
> counter = 0
> for lw, lg in zip(word, guess):
> if lw == lg:
> ret[counter] = "x"
> else:
> if lg in word:
> ret[counter] = "."
> counter += 1
> return "".join(ret)
Thx.
The problem with this may be that for example
mastermind('xxaxx','ayayy')
returns
.-x--
but I should like to have --x-- instead (at least I think so).
JB
More information about the Python-list
mailing list