Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #90745
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.046 |
| X-Spam-Evidence | '*H*': 0.91; '*S*': 0.00; 'string': 0.09; 'newline': 0.09; 'subject:characters': 0.09; 'subject:string': 0.09; 'cc:addr :python-list': 0.11; '"\\n")': 0.16; 'ah,': 0.16; 'correctness': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'newline,': 0.16; 'subject:remove': 0.16; 'two.': 0.16; 'wrote:': 0.18; 'not,': 0.20; 'cc:addr:python.org': 0.22; 'exists': 0.24; 'cc:2**0': 0.24; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'lines': 0.31; 'probably': 0.32; 'subject:the': 0.34; 'subject:from': 0.34; 'one,': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'version': 0.36; 'joined': 0.36; 'entry': 0.36; 'should': 0.36; 'two': 0.37; 'list': 0.37; 'ends': 0.38; 'mine': 0.38; 'skip:- 10': 0.38; 'expect': 0.39; 'sure': 0.39; 'how': 0.40; 'blank': 0.60; "you'll": 0.62; 'more': 0.64; 'between': 0.67; 'results': 0.69; '2015': 0.84; 'safe.': 0.84; 'subject:long': 0.84; 'subject:very': 0.91; 'to:none': 0.92; 'differences': 0.93 |
| 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:cc :content-type; bh=FyORLLxU7XYgSQw97wNWGFfhBnG5as1Ae+MRK7sans8=; b=sTrIUe9FcYO4RFGpl+kq8cu3lqdhzwG2cxioI/qeCDd7SzBx1bE+SB78S+0vbO5kzy ZW1WWC2iXhvjL0dwLiYQM3Zz2PLmVJhWSBrCVJyC2S9iKxNDqDBi8aLb2Ogz7UvrCfoc K+y1atQM0cC0XJk2rrkDjGSZonCPf4Qedo2JZWjKjf6Fzxa6zUQ8nM5LqyxtBwxdMu8+ 2Nh6oHcMzCxSGkseFQXUIaaBYmSdpLV6C8Q6tF5xz+/m9xi3PVj3Vd19yHsH7bat4Xtc 5gz1kDltOHB0nEII9ARepkF1uqX9lhFLWksPhwv/AUb2HV8UvFhTtwoR8OYcGKhYlYSr X5yg== |
| MIME-Version | 1.0 |
| X-Received | by 10.50.141.164 with SMTP id rp4mr5252793igb.2.1431795546649; Sat, 16 May 2015 09:59:06 -0700 (PDT) |
| 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> |
| Date | Sun, 17 May 2015 02:59:06 +1000 |
| Subject | Re: Fastest way to remove the first x characters from a very long string |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <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.78.1431795548.17265.python-list@python.org> (permalink) |
| Lines | 28 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1431795548 news.xs4all.nl 2872 [2001:888:2000:d::a6]:47939 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:90745 |
Show key headers only | View raw
On Sun, May 17, 2015 at 2:22 AM, <bruceg113355@gmail.com> wrote:
> # Original Approach
> # -----------------
> ss = ss.split("\n")
> ss1 = ""
> for sdata in ss:
> ss1 = ss1 + (sdata[OFFSET:] + "\n")
>
>
> # Chris's Approach
> # ----------------
> lines = ss.split("\n")
> new_text = "\n".join(line[8:] for line in lines)
Ah, yep. This is exactly what str.join() exists for :) Though do make
sure the results are the same for each - there are two noteworthy
differences between these two. Your version has a customizable OFFSET,
where mine is hard-coded; I'm sure you know how to change that part.
The subtler one is that "\n".join(...) won't put a \n after the final
string - your version ends up adding one more newline. If that's
important to you, you'll have to add one explicitly. (I suspect
probably not, though; ss.split("\n") won't expect a final newline, so
you'll get a blank entry in the list if there is one, and then you'll
end up reinstating the newline when that blank gets joined in.) Just
remember to check correctness before performance, and you should be
safe.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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