Question on for loop

leo kirotawa kirotawa at gmail.com
Mon Mar 4 07:59:40 EST 2013


In fact this code is already doing what you want, but if the second
character, by example, is not in secrectWord it'll jump out of the for and
return. If you want that interact through the all characters and  maybe
count how many them are in the secrectWord, just take of the return there
or do some list comprehension like: [ r for r in secrecWord if r in
lettersGuessed] .



[]'s



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

> Hi all,
>
> I'm super new to python, just fyi.
>
> 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:
>         return True
> return False
>
> Thanks!
>
> Ro
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Leônidas S. Barbosa (Kirotawa)

Engenheiro de Software - IBM (LTC - Linux Technology Center)
MsC Sistemas e Computação
Bacharel em Ciências da Computação.

blog nerd: corecode.wordpress.com/

<http://corecode.wordpress.com/>User linux : #480879

"Mais sábio é aquele que sabe que não sabe" (Sócrates)
"smile and wave" - =D + o/ (Penguins of Madagascar)

日本語の学生です。
コンピュータサイエンスの学位.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130304/67a5e325/attachment.html>


More information about the Python-list mailing list