[Python-ideas] Integrate some itertools into the Python syntax

Franklin? Lee leewangzhong+python at gmail.com
Mon Mar 28 10:45:27 EDT 2016


I'm still very uneasy about how slicing is usually random access, and
doesn't change how it indexes its elements from repeated use. It means that
you have something very different for the same syntax.

(No interest in `my_iterator(:)`? It might actually be compatible with
existing syntax.)

What about

    IterTool(foo).islice(dropuntil_f, take_while_g, filter_h)

Keeps it as a single call but with explicit call syntax. Won't most uses
stick something complicated (= long) in the slice?
On Mar 27, 2016 11:31 PM, "Chris Barker - NOAA Federal" <
chris.barker at noaa.gov> wrote:

> Oops, hit send by accident.
>
> >
> >>> for line in the_file[:10]:
> >>>  ...
> >>>
> >>> arrgg! files are not indexable!.
> >>
> >> No, they are *enumerable*:
> >>
> >>   for i, line in enumerate(the_file):
> >>       if i >= 10: break
> >>       ...
> >>
> >> I guess your request to make iterators more friendly is a good part of
> >> why enumerate() got promoted to builtin.
> >
> > Sure, but you have to admit that the slicing notation is a lot
> > cleaner. And I don't WANT to enumerate -/ I want
> I want to iterate only the first n items -- that may be a common
> enough use case for a concise notation.
>
> >> takewhile or dropwhile from itertools is your friend.  (I have no
> >> opinion -- not even -0 -- on whether promoting those functions to
> >> builtin is a good idea.)
>
> Well this thread started with those ideas ....
>
> My point is still : making working with iteratables as easy and
> natural as sequences is a good direction to go.
>
> -CHB
>
>
>
> >>
> >>> But aside from that -- just the idea that looking at how to make
> >>> iterable a more "natural" part of the language is a good thing.
> >>
> >> I think it's from Zen and the Art of Motorcycle Maintenance (though
> >> Pirsig may have been quoting), but I once read the advice: "If you
> >> want to paint a perfect painting, make yourself perfect and then paint
> >> naturally."  I think iterators are just "unnatural" to a lot of
> >> people, and will remain unnatural until people evolve.  Which they may
> >> not!
> >>
> >> Real life "do until done" tasks are careers ("do ... until dead") or
> >> have timeouts ("do n times: break if done else ...").  In computation
> >> that would be analogous to scrolling a Twitter feed vs. grabbing a
> >> pageful.  In the context of this discussion, a feed is something you
> >> wait for (and maybe timeout and complain to the operator if it blocks
> >> too long), while you can apply len() to pages.  And you know which is
> >> which in all applications I've dealt with -- except for design of
> >> abstract programming language facilities like "for ... in".  The point
> >> being that "real life" examples don't seem to help people's intuition
> >> on the Python versions.
> >>
> >>
> >>
> _______________________________________________
> 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/20160328/fb2f8315/attachment.html>


More information about the Python-ideas mailing list