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: 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 Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Sat, May 16, 2015 at 9:28 AM, 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