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

Bruce Leban bruce at leapyear.org
Fri Jan 3 19:11:59 CET 2014


On Fri, Jan 3, 2014 at 6:17 AM, Joshua Landau <joshua at landau.ws> wrote:

> OTOH, to many non-mathematical people I hardly expect "is this scalar"
> to feel nearly as meaningful a question as "is this atomic".
>
> To bike-shed, how about "unitary".
>

"atomic" has the wrong meaning since it says it doesn't have any component
parts. Scalar has the right meaning.

As to the idea of making strings not iterable, that would break my code. I
write a lot of code to manipulate words (to create puzzles) and iterating
over strings is fundamental. In fact, I'd like to have strings as results
of iteration operations on strings:

>>> sorted('string')
'ginrst'
>>> list(itertools.permutations('bar'))
['bar', 'bra', 'abr', 'arb', 'rba', 'rab']


instead I have to write

>>> ''.join(sorted('string'))
>>> [''.join(s) for s in itertools.permutations('bar')]


This would probably break less code than making strings non-iterable, but
realize that there's approximately 0% chance this would ever change and
there's no easy way to cover every iteration operation. And it would
confuse people if sometimes:

(x.upper() for x in s)


returned an iterator and sometimes it returned a string.

--- Bruce
My guest puzzle for Puzzles Live: http://www.puzzazz.com/puzzles-live/10
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140103/29607c44/attachment.html>


More information about the Python-ideas mailing list