Thoughts on List Methods and Return Values

Alex Martelli aleaxit at
Sat Feb 17 19:02:12 CET 2001

"Don O'Donnell" <donod at> wrote in message
news:3A8E44E3.3E25C7B3 at
> Methods that return None:
> append, extend, insert, remove, reverse, sort
> Which leads me to the thought that if *all* the methods which now return
> None were to modify the list in place as well as return the modified
> list, we would soon get used to this behaviour and achieve some coding
> economy by being able to chain operations.
> I'm just throwing this out for discussion, knowing that it has no chance
> of being implemented since it would break a lot of code.

Quite apart from any evaluation of this proposal, I fail to see what 'lot of
code' could possibly be broken by this change.  Is there a 'lot of code'
_relying_ on the None return, e.g.:
    foo = alist.sort()
as a shorthand for
    foo = None
...???  I sure hope not, and what code IS there that relies on this (if any)
somewhat looks like code that *deserves* to break...:-).


More information about the Python-list mailing list