Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90744

Re: Fastest way to remove the first x characters from a very long string

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 <ian.g.kelly@gmail.com>
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 <f3836ca1-3f87-4c5c-9839-4d8a35aa77e4@googlegroups.com>
References <6a383ce2-5975-4225-b4f2-f744c9d7a516@googlegroups.com> <mailman.72.1431783967.17265.python-list@python.org> <4272d9d9-3d5b-4b8b-9875-6b66634b490c@googlegroups.com> <measurements-20150516160609@ram.dialup.fu-berlin.de> <f3836ca1-3f87-4c5c-9839-4d8a35aa77e4@googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
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 <python-list@python.org>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.77.1431795491.17265.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Sat, May 16, 2015 at 10:22 AM,  <bruceg113355@gmail.com> 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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Fastest way to remove the first x characters from a very long string bruceg113355@gmail.com - 2015-05-16 06:28 -0700
  Re: Fastest way to remove the first x characters from a very long string Joel Goldstick <joel.goldstick@gmail.com> - 2015-05-16 09:43 -0400
  Re: Fastest way to remove the first x characters from a very long string Chris Angelico <rosuav@gmail.com> - 2015-05-16 23:45 +1000
    Re: Fastest way to remove the first x characters from a very long string bruceg113355@gmail.com - 2015-05-16 07:02 -0700
      Re: Fastest way to remove the first x characters from a very long string bruceg113355@gmail.com - 2015-05-16 09:22 -0700
        Re: Fastest way to remove the first x characters from a very long string Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-16 10:57 -0600
        Re: Fastest way to remove the first x characters from a very long string Chris Angelico <rosuav@gmail.com> - 2015-05-17 02:59 +1000
          Re: Fastest way to remove the first x characters from a very long string bruceg113355@gmail.com - 2015-05-16 10:35 -0700
            Re: Fastest way to remove the first x characters from a very long string Cameron Simpson <cs@zip.com.au> - 2015-05-17 08:41 +1000
  Re: Fastest way to remove the first x characters from a very long string Grant Edwards <invalid@invalid.invalid> - 2015-05-16 14:59 +0000
    Re: Fastest way to remove the first x characters from a very long string Rustom Mody <rustompmody@gmail.com> - 2015-05-16 08:13 -0700
      Re: Fastest way to remove the first x characters from a very long string bruceg113355@gmail.com - 2015-05-16 09:24 -0700
        Re: Fastest way to remove the first x characters from a very long string Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2015-05-16 18:55 +0200
  Re: Fastest way to remove the first x characters from a very long string Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-16 23:24 +0000

csiph-web