[Python-ideas] strings as iterables - from str.startswith taking any iterator instead of just tuple

Alexander Heger python at 2sn.net
Sat Jan 4 05:23:59 CET 2014


> On Fri, Jan 3, 2014 at 2:54 PM, Alexander Heger <python at 2sn.net> wrote:
>> Generally, I find strings being iterables of characters as useful as
>> if integers were iterables of bits.  They should just be units.
>
> What this would mean is that any time you want to iterate over the
> characters, you'd have to iterate over string.split('') instead. So
> the question is, is that common enough to be a problem?

you could still have had str.iter()

> The other point that comes to mind is that iteration and indexing are
> closely related. I think most people would agree that "abcde"[1]
> should be 'b' (granted, there's room for debate as to whether that
> should be a one-character string or an integer with the Unicode
> codepoint, but either way); it's possible to iterate over anything by
> indexing it with 0, then 1, then 2, etc, until it raises IndexError.
> For a string to not be iterable, that identity would have to be
> broken.

OK, I admit that not being able to iterate over something that can be 
indexed may be confusing.  Though indexing of strings is somewhat 
special in many languages.

-Alexander


More information about the Python-ideas mailing list