Q:

Python Array, trying to place text file into an array

I am trying to complete a piece of coursework so need to place a text file full of key words into an array when i do it i get a type error message saying:

TypeError: 'in ' requires string as left operand, not list

What does this mean?
Here is my code:
#!/usr/bin/python

array = []
with open("test.txt", "r") as f:
  for line in f:
    array.append(line)
print array

searchfile =open('test.txt','r')
for line in searchfile:
    if array in line: print line
searchfile.close()

EDIT: Thank you for the reply i have changed the line to display this: 
searchfile =open('test.txt','r')
for line in searchfile:
    if line in array: print line
searchfile.close() 

The search works except i have a keywords document containing simple words like 'green, blue etc' (all on their own line) i then have a document with text such as 'my shirt is green' when i use this code it wont find anything but if i change the sentence to just a word it will find it. i need it to search a document for keywords and then display the whole line that it was in.

A:

It means that you're attempting to check whether a list is in a string, with this line:
if array in line:

My guess is you're attempting to check if the line is in array, so your in statement must be reversed:
if line in array:

So that you aren't confused by errors like this in the future, note that in is an operator. The left operand is whatever object that is to the left of your operator which is part of the in operation. From there, it's pretty clear if you look at types what the error is indicating.  

