4 ms·
If 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 thr
by archgoon 3y ago
If 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]