📌  相关文章
📜  从列表中删除项目 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:30.082000             🧑  作者: Mango

代码示例5
def remove_all(items, item_to_remove):
    if not isinstance(items, list):
        raise TypeError(f'invalid list type {type(items).__name__}')

    last_occurrence = False
    while not last_occurrence:
        try:
            items.remove(item_to_remove)
        except ValueError:
            last_occurrence = True