X-FeedAbuse: http://nntpfeed.proxad.net/abuse.pl feeded by 195.154.70.45 Path: csiph.com!usenet.pasdenom.info!nntpfeed.proxad.net!news.redatomik.org!newsfeed.xs4all.nl!newsfeed2a.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.035 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; '16,': 0.03; 'subject:characters': 0.09; 'subject:string': 0.09; 'python': 0.11; 'already,': 0.16; 'subject:remove': 0.16; 'substitute': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'looks': 0.24; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'lines': 0.31; 'skip:m 30': 0.32; 'subject:the': 0.34; "i'd": 0.34; 'subject:from': 0.34; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'to:addr:python.org': 0.39; 'enough': 0.39; 'expression': 0.60; 'map': 0.64; '2015': 0.84; 'subject:long': 0.84; 'subject:very': 0.91 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=cTW6P+78PgNTaC8fHAa5DEJMCZBLm/utTrxoiWzSwRk=; b=bzi6e04AooF5/th2HQfNWLyMylvsC2wP+0zW0ioFi9I0mGWLKCWrx5+dDmSVEHRkG1 /wcci6uTW6kIaeoTJR2L0s3PO/PqXi5OqeDuq3APTJMV2v2bx1rfYAigN3h53gOfwVFI WYY+SNYJKoEGINeX32NhMQmRZEFiHc88x/LsWLAqiRnIchyl9ClPaHYGARaJUpQbuUF6 vuRZhXLK/MRQIxSuEXfpsawsD0paqeyPplzMI5oX0VcEBHZ/QywyBQ6XCbRfj0g9HBRK 6fXdK8iKnzNKSxksOTy+8Iv3YI+1KchENFcfXNOOy9ymmHENZeIqMcG8f+ch4gz4VNQj G9uA== X-Received: by 10.107.17.29 with SMTP id z29mr15245139ioi.69.1431795483763; Sat, 16 May 2015 09:58:03 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <6a383ce2-5975-4225-b4f2-f744c9d7a516@googlegroups.com> <4272d9d9-3d5b-4b8b-9875-6b66634b490c@googlegroups.com> From: Ian Kelly Date: Sat, 16 May 2015 10:57:23 -0600 Subject: Re: Fastest way to remove the first x characters from a very long string To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 1431795491 news.xs4all.nl 2936 [2001:888:2000:d::a6]:46775 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90744 On Sat, May 16, 2015 at 10:22 AM, wrote: > # Chris's Approach > # ---------------- > lines = ss.split("\n") > new_text = "\n".join(line[8:] for line in lines) Looks like the approach you have may be fast enough already, but I'd wager the generator expression could be replaced with: map(operator.itemgetter(slice(8, None)), lines) for a modest speed-up. On the downside, this is less readable. Substitute itertools.imap for map if using Python 2.x.