[Python-ideas] Integrate some itertools into the Python syntax
Brendan Barnwell
brenbarn at brenbarn.net
Tue Mar 22 14:53:46 EDT 2016
On 2016-03-21 16:59, Michel Desmoulin wrote:
> The solution I'm currently using involves having a class called g, and
> everytime I want to manipulate an iterable, I just wrap it in g().
>
> Then I got an object with all those semantics (and actually a lot more).
I'm not sure I see the value in new syntax, but I think what you
describe here would be a useful addition to itertools. Yes, you would
still have to import itertools, but you could just import this one
"convenient iterator" class and use that, which could allow for concise
but readable code that otherwise would have to use many different
itertools functions. It would require some thought about what sorts of
overloaded operators (if any) would be appropriate for various itertools
functions, but I think it could still be a gain even if the main
advantage was just being able to write stuff like
"niceIterator(x)[10:20] + niceIterator(y)[20:30]". Since it would just
be a convenience wrapper, there need be no worries about it not working
for particular kinds of iterables (e.g., ones that already define their
own behavior for certain operators); you just wouldn't use it for ones
where it masked behavior you cared about on the underlying iterable.
--
Brendan Barnwell
"Do not follow where the path may lead. Go, instead, where there is no
path, and leave a trail."
--author unknown
More information about the Python-ideas
mailing list