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


Groups > comp.lang.python > #90730

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

Path csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <joel.goldstick@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.015
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; '16,': 0.03; 'string.': 0.05; 'string': 0.09; 'iterate': 0.09; 'subject:characters': 0.09; 'subject:string': 0.09; 'cc:addr:python-list': 0.11; '":"': 0.16; '"some': 0.16; 'formatted': 0.16; 'hexadecimal': 0.16; 'subject:remove': 0.16; 'sat,': 0.16; 'thanks,': 0.17; 'wrote:': 0.18; 'split': 0.19; 'not,': 0.20; 'bruce': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'characters': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'text': 0.33; 'url:python': 0.33; 'subject:the': 0.34; 'subject:from': 0.34; 'convert': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'method': 0.36; 'url:org': 0.36; 'searching': 0.37; 'too': 0.37; 'list': 0.37; 'url:mail': 0.40; 'remove': 0.60; 'removing': 0.60; 'first': 0.61; 'back': 0.62; 'million': 0.74; 'as:': 0.81; '2015': 0.84; 'subject:long': 0.84; 'joel': 0.91; 'subject:very': 0.91; 'to:none': 0.92
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=UfDrSfj1D7gHSJir3E541xE+jDsO8hDP4CXKYFQ6aGE=; b=e81Slg0YInVrXbVvnJJQf1mjb5s8gwVIUD8IM7t6bDBr+O9UvfE+8TqZIVlxMKSDUa moutznQO3+W45bx44nkUViAEmxke7zPeI1K9cRCcj8GJSz6Lu3Oz5Et3jM5p/4KMBZZB 5aW+h99d2doSQGBk2fq/5KXv7XJ090UAOehh8Lz1OfQ/M6ugUkvfte+o+2dGCKGc6gEk tzpyObGxSE7BeN4KEQ/qMZ4Ts+pDFDTWrA4/sPeVSdHaT0re1Ar0BEzZj9hIQ3KkQoAI I5Rb+QUajDx+rN4Ec4m6YxeJ7Unkzg/UJ55oyQ/MMpPx/MO8khW3eVKz5nvJBlTKYm5c w0xw==
MIME-Version 1.0
X-Received by 10.107.47.216 with SMTP id v85mr6225122iov.86.1431783815777; Sat, 16 May 2015 06:43:35 -0700 (PDT)
In-Reply-To <6a383ce2-5975-4225-b4f2-f744c9d7a516@googlegroups.com>
References <6a383ce2-5975-4225-b4f2-f744c9d7a516@googlegroups.com>
Date Sat, 16 May 2015 09:43:35 -0400
Subject Re: Fastest way to remove the first x characters from a very long string
From Joel Goldstick <joel.goldstick@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.71.1431783817.17265.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1431783817 news.xs4all.nl 2878 [2001:888:2000:d::a6]:50981
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:90730

Show key headers only | View raw


On Sat, May 16, 2015 at 9:28 AM,  <bruceg113355@gmail.com> wrote:
> I have a string that contains 10 million characters.
>
> The string is formatted as:
>
> "0000001 : some hexadecimal text ... \n
> 0000002 : some hexadecimal text ... \n
> 0000003 : some hexadecimal text ... \n
> ...
> 0100000 : some hexadecimal text ... \n
> 0100001 : some hexadecimal text ... \n"
>
> and I need the string to look like:
>
> "some hexadecimal text ... \n
> some hexadecimal text ... \n
> some hexadecimal text ... \n
> ...
> some hexadecimal text ... \n
> some hexadecimal text ... \n"
>
> I can split the string at the ":" then iterate through the list removing the first 8 characters then convert back to a string. This method works, but it takes too long to execute.
>
> Any tricks to remove the first n characters of each line in a string faster?
>
slicing might be faster than searching for :

Do you need to do this all at once?  If not, use a generator

> Thanks,
> Bruce
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com

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