【发布时间】:2021-07-21 09:16:15
【问题描述】:
有这样一个字符串:
machine1 volumename1 space1
machine1 volumename2 space2
machine2 volumename1 space1
machine2 volumename2 space2
machine3 volumename1 space1
我想删除包含一个列表元素的所有行,例如:
list = ["machine1", "machine3"]
最后收到这样的东西:
machine2 volumename1 space1
machine2 volumename2 space2
我试过这个,但它返回一个列表,我不想改变字符串的原始格式,我想使用一个机器列表作为输入:
output = str([line for line in output.split('\n') if 'machine1' not in line and 'machine3' not in line])
【问题讨论】: