[Python-ideas] strings as iterables - from str.startswith taking any iterator instead of just tuple
Amber Yust
amber.yust at gmail.com
Sun Jan 5 01:08:13 CET 2014
__fromiter__, anyone?
On Sat Jan 04 2014 at 3:31:59 PM, Masklinn <masklinn at masklinn.net> wrote:
> On 2014-01-04, at 23:59 , Steven D'Aprano <steve at pearwood.info> wrote:
> > On Sat, Jan 04, 2014 at 11:22:16AM +0100, spir wrote:
> >> On 01/03/2014 07:11 PM, Bruce Leban wrote:
> >>> 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']
> >
> > That would be nice to have.
>
> More generally, it would be nice if a sequence type could specify how to
> derive a new instance of itself (from an iterable for instance).
> Constructors don't necessarily work (e.g. str's constructor). Clojure
> has such a concept through the IPersistentCollection protocol:
> empty(coll) creates a new (empty) instance of coll (clojure's
> collections being immutable, it makes sense to create an empty
> collection then add stuff into it via into() or conj())
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140105/77c89d06/attachment.html>
More information about the Python-ideas
mailing list