Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subsequent': 0.05; 'subject:Python': 0.06; 'indexing': 0.07; 'string': 0.09; '%s"': 0.09; 'counting': 0.09; 'cc:addr:python-list': 0.11; "wouldn't": 0.14; '-tkc': 0.16; 'finds': 0.16; 'for,': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'internally': 0.16; 'presume': 0.16; 'subject:Unicode': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'example': 0.22; 'cc:addr:python.org': 0.22; 'string,': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'tim': 0.29; 'characters': 0.30; 'start,': 0.30; "i'm": 0.30; 'lines': 0.31; 'chase': 0.31; 'file': 0.32; 'thanks!': 0.32; 'beginning': 0.33; 'could': 0.34; 'but': 0.35; 'charset:us-ascii': 0.36; 'subject:?': 0.36; 'mapping': 0.38; 'even': 0.60; 'most': 0.60; 'to:addr:gmail.com': 0.65; 'skip:r 30': 0.69; 'glad': 0.83; 'received:50.22': 0.84; 'worth,': 0.84; 'subject:you': 0.87 Date: Tue, 3 Jun 2014 21:37:17 -0500 From: Tim Chase To: Chris Angelico Subject: Re: Unicode and Python - how often do you index strings? In-Reply-To: References: <20140603201154.38b47afb@bigbox.christie.dr> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.com Cc: "python-list@python.org" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1401849477 news.xs4all.nl 2863 [2001:888:2000:d::a6]:41055 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72581 On 2014-06-04 12:16, Chris Angelico wrote: > On Wed, Jun 4, 2014 at 11:11 AM, Tim Chase > wrote: > > I then take row 2 and use it to make a mapping of header-name to a > > slice-object for slicing the subsequent strings: > > > > slice(i.start(), i.end()) > > > > print("EmpID = %s" % row[header_map["EMPID"]].strip()) > > print("Name = %s" % row[header_map["NAME"]].strip()) > > > > which I presume uses string indexing under the hood. > > Yes, it's definitely going to be indexing. If strings were > represented internally in UTF-8, each of those calls would need to > scan from the beginning of the string, counting and discarding > characters until it finds the place to start, then counting and > retaining characters until it finds the place to stop. Definite > example of what I'm looking for, thanks! For what it's worth, most of the lines in each file are under ~2k, so even O(N) or O(log N) indexing wouldn't be grievous. Noticeable, but not grievous. Glad my example could give you some fodder. -tkc