Question on for loop

Bryan Devaney bryan.devaney at gmail.com
Tue Mar 5 06:12:47 EST 2013


On Monday, March 4, 2013 4:37:11 PM UTC, Ian wrote:
> 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.

You are correct. sorry for the misleading answer, was digging through old shell scripts all day yesterday and brain was obviously not not the better for it.



More information about the Python-list mailing list