Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed2.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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:file': 0.07; 'subject:two': 0.07; 'wednesday,': 0.07; 'iterate': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '3):': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'print': 0.22; 'header:User- Agent:1': 0.23; 'example.': 0.24; 'header:X-Complaints-To:1': 0.27; 'asked': 0.31; 'that.': 0.31; 'actual': 0.34; 'subject:with': 0.35; 'requirement': 0.35; 'thanks': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'break': 0.61; 'till': 0.61; 'more': 0.64; 'detail.': 0.68; 'otten': 0.84; 'subject:over': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: iterating over a file with two pointers Date: Wed, 18 Sep 2013 14:54:42 +0200 Organization: None References: <3018b3d4-f914-4c89-9f26-cd4b2af32e73@googlegroups.com> <0142cea2-e534-47d0-92fe-79a87068c497@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084b6fc.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1379508875 news.xs4all.nl 15912 [2001:888:2000:d::a6]:45830 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54378 nikhil Pandey wrote: > On Wednesday, September 18, 2013 5:14:10 PM UTC+5:30, Peter Otten wrote: > I want to iterate in the inner loop by reading each line till some > condition is met.how can i do that. Thanks for this code. That's not what I had in mind when I asked you to >> describe your actual requirement in more detail. Anyway, change [...] >> f, g = tee(f) >> for inner in islice(g, 3): >> print " ", inner, >> break [...] to f, g = tee(f) for inner in g: if some condition: break print " ", inner, break in my example.