4 ms·
> And for this reason, String iteration should be based on codepoints Why not offer both and be clear about it? Rather than just "length", why not call them co
by grumpyprole 3y ago
> And for this reason, String iteration should be based on codepoints
Why not offer both and be clear about it? Rather than just "length", why not call them code points? The Python docs for "len" which can be called on a unicode string say "Return the length (the number of items) of an object.". It doesn't look like a clear and easy to use API to me.
- archgoon 3y agoIf you insist that `len` shouldn't be defined on strings, and the default iterator should be undefined in python then: for c in "Hello": pass should throw an exception. Also if word[0] == 'H': pass should throw an exception. This would have been an extremely controversial suggestion when python3 came out to say the least. Codepoints is a natural way of defining unicode strings in python, and it mostly works the way you expect once you give it a bit of thought. It is lower level than, say, grapheme clusters, but its more well defined and it provides the proper primitives for dealing with all use cases.
- grumpyprole 3y agoI would suggest that len works as the article suggests; and "Hello".codepoints gives the behaviour you want.
- archgoon 3y ago[dead]