【发布时间】:2018-02-17 17:44:16
【问题描述】:
这是一个示例代码
with open('somefile.txt', 'r') as file:
for line in file:
find = 'some string'
if find in line:
if previous line is the same as this line: #how to write this ?
pass
else:
print(line)
如何在这段代码中编写第 5 行?
【问题讨论】:
-
或者,不要回头看,而是在一行包含您的字符串时记下,并检查下一行是否也包含。
标签: python python-3.x