Searching for strings and locating the line numbers that strings are located in [PYTHON]
<p>How can I search for strings and locate the line numbers that strings are located in?</p>

<p>For example</p>

<pre><code>&gt;&gt;&gt; findlinenb('example.txt', ['desktop', 'connection', 'processor'])
desktop in 23
connection in 35, 38, 35
processor in 4, 5, 6, 8
</code></pre>

<p>My code:</p>

<pre><code>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)
</code></pre>

<p>Any ideas or suggestions is greatly appreciated.</p>

<p>Peter</p>
