Unicode and Python - how often do you index strings?

Chris Angelico rosuav at gmail.com
Wed Jun 4 05:30:11 EDT 2014


On Wed, Jun 4, 2014 at 6:22 PM, Mark Lawrence <breamoreboy at 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



More information about the Python-list mailing list