faqts : Computers : Programming : Languages : Python : Snippets : Lists

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 6 people (67%) answered Yes
Recently 3 of 5 people (60%) answered Yes

Entry

list.without()? (Removing element from list)

Jul 5th, 2000 10:02
Nathan Wallace, unknown unknown, Hans Nowak, Snippet 285, Magnus L. Hetland


"""
Packages: basic_datatypes.lists
"""
"""
Whoa!
Why on *earth* would you use a while/try/break-combination? IMO a much
more natural solution would be:
"""
def without(source, element):
    result = source[:]
    while element in result:    # changed by PSST; while <- if
        result.remove(element)
    return result
"""
My point was that I wanted a method in the standard libraries, or,
preferrably as a list method. I guess the closest I got wat the filter
suggestion.
"""