Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.datemas.de!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4.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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; '(at': 0.04; 'lines,': 0.07; 'string': 0.09; 'runs': 0.10; 'python': 0.11; 'characters:': 0.16; 'file-like': 0.16; 'iterates': 0.16; 'iterator': 0.16; 'looping': 0.16; 'wrote:': 0.18; 'basically': 0.19; 'question': 0.24; 'header:In-Reply-To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; '13,': 0.31; 'file': 0.32; 'objects': 0.35; 'received:google.com': 0.35; 'subject:New': 0.37; 'too': 0.37; 'skip:o 20': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'subject:. ': 0.67; 'subject:For': 0.78; 'fin': 0.84; 'treating': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=gyT7rorC5FTTWIOXUlcde2pJ6zjV3AA8QAlPZoZ2NjE=; b=dTySDlDnubPreESWHYzDVzt3lVC08EiJf9y0CWXCAlncz8ZoalcMyY4PpLOvWWTFMF 5ibgnapXbEV/WaP9OcK4RxkbE1FZM+31sGNJMR33oKPBfHm021utvCVRHS455vzzjjrr e5dQD3tXYQDpuJCYsquF8R1WF0Zt1q4FHQxIBle9VTD337Z3WTGBHxnFhJ2CN5E8uvFY N2X89R1Cxb8YIZPmI9xafpToiVyc2Z1UrAzEPPH0TLAWlvBW4CXk31SS23Un7HiAy/Oc T6nyTmy6/E5LLMReUU7Rz1Jn62+4NKzmiHJQZ9TCAhsfsNbhH8EgNJGHLx0ybOF+Br4w YNhA== X-Received: by 10.68.134.198 with SMTP id pm6mr1237633pbb.9.1400039385591; Tue, 13 May 2014 20:49:45 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <2f08e970-1334-4e7f-ba84-14869708a73b@googlegroups.com> References: <2f08e970-1334-4e7f-ba84-14869708a73b@googlegroups.com> From: Ian Kelly Date: Tue, 13 May 2014 21:49:04 -0600 Subject: Re: New to Python. For in loops curiosity To: Python Content-Type: text/plain; charset=UTF-8 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: 16 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1400039394 news.xs4all.nl 2944 [2001:888:2000:d::a6]:36104 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:71529 On Tue, May 13, 2014 at 9:38 PM, Leonardo Petry wrote: > The loop below (at the bottom) runs each line of the file > > fin = open('wordplay.txt'); > user_input = raw_input('Enter some characters: ') > count = 0 > for line in fin: > word = line.strip() > if(avoids(word, user_input)): > count += 1; > > This is just too convenient. > Basically my question is: Why is python not treating the contents of wordplay.txt as one long string and looping each character? Because the iterator for file-like objects iterates over lines, not characters.