[Python-Dev] list.discard? (Re: dict.discard)

Josiah Carlson jcarlson at uci.edu
Fri Sep 22 03:02:07 CEST 2006


Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Gustavo Niemeyer wrote:
> 
> >   >>> print set.discard.__doc__
> >   Remove an element from a set if it is a member.
> 
> Actually I'd like this for lists. Often I find myself
> writing
> 
>    if x not in somelist:
>      somelist.remove(x)
> 
> A single method for doing this would be handy, and
> more efficient.

A marginal calling time improvement; but we are still talking linear
time containment test.

I'm -0, if only because I've never really found the need to use
list.remove(), so this API expansion doesn't feel necessary to me.

 - Josiah



More information about the Python-Dev mailing list