我有这段代码,如果行 3 次包含相同的字母,则删除行。如果字母重复超过 3 次(分隔),我需要它来删除该行。
3次(分开)我的意思是例如这一行BAABAAG。请注意,这一行包含该字母A四次,但我的代码没有删除它,因为这四个字母A并不彼此相邻。
bad_words = ['AAA','BBB','CCC','DDD','EEE','FFF','GGG','HHH','III','JJJ','KKK','LLL','MMM','NNN','OOO','PPP','QQQ','RRR','SSS','TTT','UUU','VVV','WWW','XXX','YYY','ZZZ','111','222','333','444','555','666','777','888','999','000']
with open('7.csv') as oldfile, open('new7.csv', 'w') as newfile:
for line in oldfile:
if not any(bad_word in line for bad_word in bad_words):
newfile.write(line)
文件样本:
BAABAAB
BAABAAC
BAABAAD
BAABAAE
BAABAAF
BAABAAG
BAABAAH
BAABAAI
BAABAAJ
BAABAAK
BAABAAL
BAABAAM
BAABAAN
BAABAAO
BAABAAP
BAABAAQ
慕婉清6462132
四季花海
慕妹3242003
神不在的星期二
相关分类