Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #13236

Re: PyWart: Itertools module needs attention

References <f0f36335-b077-41a5-9f40-ca9b0dd8e96d@24g2000yqr.googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2011-09-13 09:45 -0600
Subject Re: PyWart: Itertools module needs attention
Newsgroups comp.lang.python
Message-ID <mailman.1075.1315928745.27778.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Sep 12, 2011 at 4:04 PM, rantingrick <rantingrick@gmail.com> wrote:
>
> ############################################################
> #                          Quote                           #
> ############################################################
> # The itertools module is great HOWEVER i believe most     #
> # people are recreating the functionalities due to the     #
> # insanely cryptic and/or missing examples from each       #
> # method                                                   #
> ############################################################

Have you looked at the online itertools documentation at all?

http://docs.python.org/library/itertools.html

> py> ''.join(list(itertools.dropwhile(lambda x:x==" ", "    hello
> word    ")))
> 'hello word    '
> py> ''.join(list(itertools.takewhile(lambda x:x==" ", "    hello
> word    ")))
> '    '

These are too complex to be good examples.  Drop the lambda and
replace it with a built-in.  Also, str.join is perfectly capable of
taking an iterator as its argument.  There is no reason at all to
construct a list first.

> py> print itertools.compress.__doc__
> compress(data, selectors) --> iterator over selected data
> Return data elements corresponding to true selector elements.
> Forms a shorter iterator from selected data elements using the
> selectors to choose the data elements.
>
> ############################################################
> #                          Quote                           #
> ############################################################
> # WTF! Would you like to define a Python "selector". Could #
> # it be that we should be using "selector function" or     #
> # "predicate function" instead?                            #
> ############################################################

Notice that it says "selector elements", not "selector functions".
You have misconstrued what this function does.  Hint: it does not use
predicates at all.

I can agree though that this could probably use a simple example in
the doc string.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

PyWart: Itertools module needs attention rantingrick <rantingrick@gmail.com> - 2011-09-12 15:04 -0700
  Re: PyWart: Itertools module needs attention Ethan Furman <ethan@stoneleaf.us> - 2011-09-12 16:29 -0700
  Re: PyWart: Itertools module needs attention Ian Kelly <ian.g.kelly@gmail.com> - 2011-09-13 09:45 -0600
    Re: PyWart: Itertools module needs attention rantingrick <rantingrick@gmail.com> - 2011-09-13 19:08 -0700

csiph-web