使用列表表达式即可边遍历边删除
MyList = [{"test": "666"}, {"test": "123"}, {"test": "123"}, {"test": "123"}]
MyList = [x for x in MyList if x["test"] != "666"]
输出
[{'test': '123'}, {'test': '123'}, {'test': '123'}]
使用列表表达式即可边遍历边删除
MyList = [{"test": "666"}, {"test": "123"}, {"test": "123"}, {"test": "123"}]
MyList = [x for x in MyList if x["test"] != "666"]
输出
[{'test': '123'}, {'test': '123'}, {'test': '123'}]