Question on for loop

Joel Goldstick joel.goldstick at gmail.com
Mon Mar 4 08:04:58 EST 2013


On Mon, Mar 4, 2013 at 7:18 AM, newtopython <roshen.sethna at gmail.com> wrote:

> Hi all,
>
> I'm super new to python, just fyi.
>

Welcome.  Next time write a better subject line, and be sure the code you
post is actually the code you are running.  Provide the results you want
and what you get.  Provide the traceback if there is one

>
> In the piece of code below, secretWord is a string and lettersGuessed is a
> list. I'm trying to find out if ALL the characters of secretWord are
> included in lettersGuessed, even if there are additional values in the
> lettersGuessed list that aren't in secretWord.
>
> What this code is doing is only checking the first character of secretWord
> and then returning True or False. How do I get it to iterate through ALL of
> the characters of secretWord?
>
> for character in secretWord:
>         if character not in lettersGuessed:
>

I am guessing that the next two lines are actually indented in your script
so I am changing them here


            return True
>         return False
>
> The first time your if block is checked it will return True or False.
Since you haven't shown this code in a function, as written it won't run at
all.

Your question makes no sense.  What would it mean to look through each
character and return True or False?  What would make the result True?  All
matches, some matches?

> Thanks!
>
> Ro
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130304/f8613ff8/attachment.html>


More information about the Python-list mailing list