list.without()?

Fredrik Lundh fredrik at pythonware.com
Tue Nov 16 04:59:32 EST 1999


Magnus L. Hetland <mlh at vier.idi.ntnu.no> wrote:
> Why on *earth* would you use a while/try/break-combination?

maybe because the meaning of "without a
specified element" is unclear.  mike's version
guarantees that:

    list.without(element)
    assert element not in list

never fails, while your version behaves just
like "remove" -- if there are several instances
of an element value, only the first one is
removed:

    count = list.count(element)
    list.without(element)
    assert count == 0 or list.count(element) == count-1

in either case, adding "without" (like remove, but
returns a new list) strikes me as being even more
contrived than earlier proposals like "sorted" (like
sort, but returns a new list), etc.

</F>





More information about the Python-list mailing list