[Python-Dev] Why not Lisp-like list-related functions ?

Fredrik Lundh fredrik@pythonware.com
Wed, 13 Jun 2001 19:06:52 +0200


Dmitry wrote:
> I'm new to Python but quite familiar with Lisp. So my question is
> about Python list-related functions. Why append(), extend(), sort(),
> reverse() etc. doesn't return a reference to it's own (modified)
> argument ?

doesn't Lisp have a FAQ? ;-)

    http://www.python.org/doc/FAQ.html#6.20
    Q. Why doesn't list.sort() return the sorted list?

...

basically, operations that modify an object generally don't return
the object itself, to avoid mistakes like:

    for item in list.reverse():
        print item # backwards
    ...
    for item in list.reverse():
        print item # backwards, or?

a slightly more pythonic way would be to add sorted, extended,
reversed (etc) -- but that leads to method bloat.

in addition, based on studying huge amounts of python code, I
doubt cascading list operations would save the world that much
typing...

followups to python-list@python.org

</F>