On 18/11/2013 14:31, Piet van Oostrum wrote:
Chris Angelico <ros...@gmail.com> writes:

On Mon, Nov 18, 2013 at 11:29 PM, Ian Kelly <ian.g.ke...@gmail.com> wrote:

On Nov 18, 2013 3:06 AM, "Chris Angelico" <ros...@gmail.com> wrote:

I'm trying to figure this out. Reading the docs hasn't answered this.
If each character in a string is a 32-bit Unicode character, and (as
can be seen in the examples) string indexing and slicing are
supported, then does string indexing mean counting from the beginning
to see if there were any surrogate pairs?

The string reference says:

"""Since a String has an underlying UTF-16 encoding, certain operations are
expensive, requiring iteration of the characters of the string. In
particular, size requires iteration of the whole string, and get(), span(),
and segment() require iteration from the beginning of the string to the
given index."""

The get and span operations appear to be equivalent to indexing and slicing.

Right, that's what I was looking for and didn't find. (I was searching
the one-page reference manual rather than reading in detail.) So, yes,
they're O(n) operations. Thanks for hunting that down.

ChrisA

It would be so much better to use the Flexible String Representation.


I agree but approximately 0.0000000142857% of the world population disagrees.

--
Python is the second best programming language in the world.
But the best has yet to be invented.  Christian Tismer

Mark Lawrence

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to