取list中不报包含5B201的数据
可以使用列表推导式,遍历列表中的元素,如果元素包含"5B201"则不加入新列表中,否则加入新列表中。
示例代码如下:
old_list = ["5B201", "5B202", "5B203", "5B204", "6B101"]
new_list = [x for x in old_list if "5B201" not in x]
print(new_list)
输出结果为:
['5B202', '5B203', '5B204', '6B101']
原文地址: https://www.cveoy.top/t/topic/nzz 著作权归作者所有。请勿转载和采集!