4 ms·
> both being iterable Which is a great thing.
by erokar 9y ago
> both being iterable
Which is a great thing.
- nnq 9y agoYeah, 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...
- mikelward 9y agoBoth being iterable is great. String iteration yielding individual characters as strings is debatable. A function or method having no way to specify that a parameter must be a list of string, then acting strangely when passed a single string is a problem that types can help with.