Question on for loop

Ian Kelly ian.g.kelly at gmail.com
Mon Mar 4 17:37:11 CET 2013


On Mon, Mar 4, 2013 at 7:34 AM, Bryan Devaney <bryan.devaney at gmail.com> wrote:
>>         if character not in lettersGuessed:
>>
>>         return True
>>
>> return False
>
> assuming a function is being used to pass each letter of the letters guessed inside a loop itself that only continues checking if true is returned, then that could work.
>
> It is however more work than is needed.
>
> If you made secretword a list,you could just
>
> set(secretword)&set(lettersguessed)
>
> and check the result is equal to secretword.

Check the result is equal to set(secretword), I think you mean.

set(secretword).issubset(set(lettersguessed))

might be slightly more efficient, since it would not need to build and
return an intersection set.

One might also just do:

all(letter in lettersguessed for letter in secretword)

Which will be efficient if lettersguessed is already a set.



More information about the Python-list mailing list