【发布时间】:2018-12-10 22:46:54
【问题描述】:
我有字符串形式的路径列表
>>> p = ['/path/one/foo.txt', '/path/two/foo.txt', '/path/three/foo.txt', '/path/four/foo.txt]
我知道我可以使用类似的方法从列表中删除包含单词的条目
>>> p = [x for x in p if 'two' not in x]
>>> p
['/path/one/foo.txt', '/path/three/foo.txt', '/path/four/foo.txt']
但是,这似乎不起作用
>>> p = [x for x in p if 'two' or 'three' not in x]
>>> p
['/path/one/foo.txt', '/path/two/foo.txt', '/path/three/foo.txt', '/path/four/foo.txt]`
如何删除p 中包含two 或three 的所有条目?
注意,我是从 dict 中的不同键中提取值 two 和 three,因此创建单个列表可能并不简单。
【问题讨论】:
标签: python string python-2.7 list filepath