Iterate over a list of strings in python
<p>I am trying to set up a data set that checks how often several different names are mentioned in a list of articles. So for each article, I want to know how often nameA, nameB and so forth are mentioned. However, I have troubles with iterating over the list. </p>

<p>My code is the following:</p>

<pre><code>for element in list_of_names:
for i in list_of_articles:
    list_of_namecounts = len(re.findall(element, i))
</code></pre>

<ol>
<li>list_of_names = a string with several names [nameA nameB nameC]</li>
<li>list_of_articles = a list with 40.000 strings that are articles </li>
</ol>

<p>Example of article in list_of_articles:</p>

<ol>
<li>Index: 1</li>
<li>Type: str </li>
<li>Size: Amsterdam - de financiële ...</li>
</ol>

<p>the error i get is: expected string or buffer</p>

<p>I though that when iterating over the list of strings, that the re.findall command should work using lists like this, but am also fairly new to Python. Any idea how to solve my issue here? </p>

<p>Thank you!</p>