Oh look, another language (ceylon)

Chris Angelico rosuav at gmail.com
Mon Nov 18 07:36:29 EST 2013


On Mon, Nov 18, 2013 at 11:29 PM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>
> On Nov 18, 2013 3:06 AM, "Chris Angelico" <rosuav at 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



More information about the Python-list mailing list