Code
text = ["300000", "300001", "500000", "500001"]
cnt = 0
for line in f:
if text in line:
print(line.strip())
cnt += 1
if cnt:
print(cnt, "count")
else:
print(text, "No data.")
Error:
Traceback (most recent call last):
File "C:/Users/users/PycharmProjects/Mining/Test Folder/Test2.py", line 10, in <module>
if text in line:
TypeError: 'in <string>' requires string as left operand, not list
Why this error occurs?
fhere?lineis a string object andtextis a list object, You are checking whether string contains list.