Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!bcyclone03.am1.xlned.com!bcyclone03.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'cpython': 0.05; 'subject:text': 0.05; 'subject:file': 0.07; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'cc:name:python list': 0.16; 'range,': 0.16; 'task.': 0.16; 'url:svn': 0.16; 'xrange': 0.16; 'wrote:': 0.18; 'select': 0.22; 'cc:addr:python.org': 0.22; 'this?': 0.23; 'mon,': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '13,': 0.31; '3.x': 0.31; 'subject:other': 0.31; 'probably': 0.32; 'text': 0.33; 'beginning': 0.33; 'subject:from': 0.34; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'read': 0.60; 'tell': 0.60; 'new': 0.61; 'zip': 0.64; 'lack': 0.78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=x2TXp1qlw6CnqGOdQeQl9tVSG/Kdpeo+lxCHtvpEvEM=; b=Qayb6rK1Iu9wblbsWVpVG7cc8beaqrPy+Dn1tiEHumMPzW8SHMRzH2OAxS5DIXtu8X s3kmdArVpzYjAdiDmPRXg9wb1X1HQe/3aIBfdSsU5VD1onL/MWfGg4nNhBqPRp+cX714 gHAqsvlF84IqTH79pJIOHFTPELsU0otrrl/K/4oSlkVRReK5KkemLIJyFEsLV+db7pFP JHkBLqIWgB+aAa+IY3zbZupcnx4aAB9E1BXVQAZ6+Hcrx9izpJhJ8ZNp1UfK1XUyhaYs cDUQ/iw38Edn+X5N7pEcJtCG/XPvLKrzQ5Z57XkJtmUfwBXAlcziN1gXKyaHCMAVUr3A RfUA== MIME-Version: 1.0 X-Received: by 10.152.25.194 with SMTP id e2mr1862352lag.32.1413246890027; Mon, 13 Oct 2014 17:34:50 -0700 (PDT) In-Reply-To: <3be64ca8-d2e7-493a-b4f3-ef114f581450@googlegroups.com> References: <3be64ca8-d2e7-493a-b4f3-ef114f581450@googlegroups.com> Date: Mon, 13 Oct 2014 17:34:49 -0700 Subject: Re: How to select every other line from a text file? From: Dan Stromberg To: Rff Content-Type: text/plain; charset=UTF-8 Cc: Python List 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: 13 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1413246898 news.xs4all.nl 2858 [2001:888:2000:d::a6]:52664 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3702 X-Received-Body-CRC: 454731259 Xref: csiph.com comp.lang.python:79073 On Mon, Oct 13, 2014 at 10:38 AM, Rff wrote: > Hi, > I have a text file. Now it is required to select every other line of that text to > generate a new text file. I have read through Python grammar, but still lack the > idea at the beginning of the task. Could you tell me some methods to get this? Perhaps something like: http://stromberg.dnsalias.org/svn/every-nth/trunk It uses zip and itertools.cycle. It's CPython 3.x though - if you need 2.x, you'd probably use xrange instead of range, and izip instead of zip.