3 ms·
Yeah, but this is a place where consistency bites your ass (in the absence of types): when you're iterating over characters in a string you usually do something
by nnq 9y ago
Yeah, but this is a place where consistency bites your ass (in the absence of types): when you're iterating over characters in a string you usually do something very very different then when you're iterating over a random list.
It could be solved by having a `string.get_iterator()` method (or `string.iterator` `@property`) for when you want to iterate over chars of a string to make it obvious (in the usual pythonic style). But probably this would break too much backward compatibility and only catch a few very easy to track bugs anyway.
Ironically, Javascript almost got this right with `string.charAt()`, but then it shoot itself in the foot by also adding `[]` operator access in its typical "let's add more ways to do it to be sure at least one of them is bound to be wrong in some context" style...