PyWart: Itertools module needs attention

Discussion in 'Python' started by rantingrick, Sep 12, 2011.

  1. rantingrick

    rantingrick Guest

    ############################################################
    # 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 #
    ############################################################

    py> print itertools.chain.__doc__
    chain(*iterables) --> chain object
    Return a chain object whose .next() method returns elements from the
    first iterable until it is exhausted, then elements from the next
    iterable, until all of the iterables are exhausted.

    ############################################################
    # Quote #
    ############################################################
    # Okay not TOO bad however this simple example would #
    # suffice: #
    ############################################################

    py> list(itertools.chain([1,2], [3,[4,5],6]))
    [1, 2, 3, [4, 5], 6]

    ############################################################
    # Quote #
    ############################################################
    # Same for these... #
    ############################################################

    py> ''.join(list(itertools.dropwhile(lambda x:x==" ", " hello
    word ")))
    'hello word '
    py> ''.join(list(itertools.takewhile(lambda x:x==" ", " hello
    word ")))
    ' '
    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? #
    ############################################################
    rantingrick, Sep 12, 2011
    #1
    1. Advertising

  2. rantingrick

    Ethan Furman Guest

    Nick Stinemates wrote:
    > I'm honestly missing the point of this mail.



    rantingrick is a well-known troll, and doesn't need to have a point.

    Please do not feed the troll.

    ~Ethan~
    Ethan Furman, Sep 13, 2011
    #2
    1. Advertising

  3. rantingrick

    Ian Kelly Guest

    On Mon, Sep 12, 2011 at 4:04 PM, rantingrick <> 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.
    Ian Kelly, Sep 13, 2011
    #3
  4. rantingrick

    rantingrick Guest

    On Sep 13, 10:45 am, Ian Kelly <> wrote:

    > Have you looked at the online itertools documentation at all?
    >
    > http://docs.python.org/library/itertools.html


    Yes the online docs are much better. I really like the source code
    showing the inner workings of the methods. However i always get upset
    when i see poorly thought out doc-strings. My philosophy is that we
    should use the built in help function first and only visit the
    documentation if more instruction is needed.


    I may need to create another PyWart on the topic of doc-strings and
    how the author of these strings needs to forget everything he knows
    and imagine he is a complete python neophyte. I remember my initial
    frustrations learning about functions (in another life it seems) and
    my inability to grasp the concept was due to poor examples. I believe
    the author use the Fibonacci sequence as an example (Python docs use
    this example also). What an idiot!

    What does conditionals, linear assignment, loops, the print function,
    in-place addition, logic, blah, blah, have to do with understanding a
    function... NOTHING! The most basic and by far the best first example
    for functions (in any language) is this...

    def add(x, y):
    return x + y

    Followed by this...

    def sub(x,y):
    return x - y

    Simple and to the point. It simply reeks of "ah ha"! I dare anyone to
    create a better introductory function example. Dear Tutorial Writer:
    When writing tutorials please check your ego at the door. Thank you.
    rantingrick, Sep 14, 2011
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven Bethard
    Replies:
    0
    Views:
    382
    Steven Bethard
    Mar 12, 2005
  2. Raymond Hettinger
    Replies:
    17
    Views:
    532
    Simon Brunning
    Feb 18, 2008
  3. rantingrick
    Replies:
    25
    Views:
    468
    Gelonida N
    Aug 3, 2011
  4. Nick Mellor
    Replies:
    35
    Views:
    336
    Paul Rubin
    Dec 6, 2012
  5. Rick Johnson

    PyWart: Module access syntax

    Rick Johnson, Jan 11, 2013, in forum: Python
    Replies:
    23
    Views:
    319
    Chris Angelico
    Jan 15, 2013
Loading...

Share This Page