Comparing element in list and string
<p>I am just learning python, and I come across the question where i have to read a file and see search for a word</p>

<p>my code is</p>

<pre><code>Search_Word = input("Type your search word : ")
file = open(input("Your file name"), 'r')
read_line = file.readlines()
file.close()

def isPartOf(read_line, Search_Word):
    x = False
    for i in range (0, len(read_line)):
        if(str(read_line[i) == Search_Word):
            x = True

    return x


isPartOf(read_line, Search_Word)
print(isPartOf(read_line, Search_Word))
</code></pre>

<p>The problem is that after I change every line into a list then compare every element in a list to user input (What i have to search)
problem is that even though element in list and user input match exactly the program does not recognize them as same thing...</p>

<p>Just replace</p>

<pre><code>for i in range (0, len(read_line)):
    if(str(read_line[i) == Search_Word):
</code></pre>

<p>by</p>

<pre><code>for i in read_line:
    if i.strip('\n') == Search_Word:
</code></pre>

python string-comparison helpers