Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.088 X-Spam-Evidence: '*H*': 0.83; '*S*': 0.00; 'subject:Question': 0.07; 'slightly': 0.15; 'bryan': 0.16; 'intersection': 0.16; 'returned,': 0.16; 'mon,': 0.16; 'wrote:': 0.17; 'assuming': 0.22; 'work.': 0.23; 'needed.': 0.23; 'pass': 0.25; 'header:In-Reply- To:1': 0.25; 'am,': 0.27; 'checking': 0.27; 'set.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'character': 0.29; 'function': 0.30; 'could': 0.32; 'skip:s 30': 0.33; 'to:addr:python-list': 0.33; 'equal': 0.33; 'received:google.com': 0.34; 'false': 0.35; 'received:209.85': 0.35; 'itself': 0.37; 'being': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'build': 0.39; 'think': 0.40; 'letters': 0.62; 'more': 0.63; '2013': 0.84; 'guessed': 0.84; 'to:name:python': 0.84; 'do:': 0.91; 'mean.': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=Cn9m6qKr2uqcZixF/3tKDvJwMDEbRPSjxQ8V22apm68=; b=KtYX6xqC5B7NFs2QTa9GjNHCkpbKDGrP5Lg/3/6mTaSYhlBBhPqoG7V9Iz1/OxM5db CGJPqgAk+4mR501VvLEPFK42OKo/SHMbVRUnCkUvXgJMMAw5y/R6mgOKGgvcBmQ4FaeR rwe1ZQ3Pge2ZFMQtI7vbUVLOybE0w6AEJpNSFkpDBCwMIxMxQfDmVzPuyNDTNDq0Rrxs MVmg/kSkVoC4cckI3zFG9fGcjbmcSwPkhhV5ax3ERCI4RjemLlLYOKJ63w53ggz0k27J Qzq7+OvC1SyEiEE6BQlgYTzWfOTqTbobKWFXSywV2/YnzUxAXnV7CpS/iDoU05t4Zv5y gtrg== X-Received: by 10.220.156.8 with SMTP id u8mr7917741vcw.24.1362415071572; Mon, 04 Mar 2013 08:37:51 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <7345f1f5-d958-4fef-ad50-81fb526b4f2f@googlegroups.com> References: <7345f1f5-d958-4fef-ad50-81fb526b4f2f@googlegroups.com> From: Ian Kelly Date: Mon, 4 Mar 2013 09:37:11 -0700 Subject: Re: Question on for loop To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362415074 news.xs4all.nl 6912 [2001:888:2000:d::a6]:33463 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40463 On Mon, Mar 4, 2013 at 7:34 AM, Bryan Devaney 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.