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


Groups > comp.lang.python > #72620

Re: Unicode and Python - how often do you index strings?

References <CAPTjJmr4iHdaCy61w2rz-oL6FcarRzzTeEU44Fxn2Z=gS0fh-Q@mail.gmail.com> <lmmkvk$73h$1@ger.gmane.org>
Date 2014-06-04 19:30 +1000
Subject Re: Unicode and Python - how often do you index strings?
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.10693.1401874213.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Jun 4, 2014 at 6:22 PM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
> Single characters quite often, iteration rarely if ever, slicing all the
> time, but does that last one count?

Yes, slicing counts. What matters here is the potential impact of
internally representing strings as UTF-8 streams; when you ask for the
Nth character, it would have to scan from either the beginning or end
(more likely beginning) of the string and count, instead of doing what
CPython 3.3+ does and simply look up the header to find out the kind,
bit-shift the index by one less than that, and use that as a memory
location.

ChrisA

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


Thread

Re: Unicode and Python - how often do you index strings? Chris Angelico <rosuav@gmail.com> - 2014-06-04 19:30 +1000

csiph-web