我有元组列表:
tupl = [('0', 'Hey'),('1', ','),('2', 'I'), ('3', 'feel'),('4', 'you'), ('5', '!')]
我想删除任何包含标点符号的元组。
我已经尝试过以下代码,但它适用于 '!',只是因为我不知道如何在此代码中放置多个条件。
out_tup = [i for i in tupl if '!' not in i]
print out_tup
如何删除所有包含标点符号(例如 ',')的元组?
请您参考如下方法:
使用任何
例如:
import string
tupl = [('0', 'Hey'),('1', ','),('2', 'I'), ('3', 'feel'),('4', 'you'), ('5', '!')]
print([i for i in tupl if not any(p in i for p in string.punctuation)])
#or
print([i for i in tupl if not any(p in i for p in [",", "!"])])
