[Python-ideas] strings as iterables - from str.startswith taking any iterator instead of just tuple
Chris Angelico
rosuav at gmail.com
Fri Jan 3 04:59:51 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?
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.
ChrisA
More information about the Python-ideas
mailing list