如何搜索字符串并定位字符串所在的行号?你知道吗
例如
>>> findlinenb('example.txt', ['desktop', 'connection', 'processor'])
desktop in 23
connection in 35, 38, 35
processor in 4, 5, 6, 8
我的代码:
def findlinenb (filename, list):
file = open(filename, "r")
content = file.read()
for i in list:
if content.find(i):
print (i, "in", content.count('\n') + 1)
如有任何意见或建议,我们将不胜感激。你知道吗
彼得
相关问题 更多 >
编程相关推荐