Python check if string got a certain word (or combination of characters)
<p>Ok so I have this string (for example):</p>

<pre><code>var = "I eat breakfast."
</code></pre>

<p>What i would like to do is to check if that string has the letters "ea", and I wanted to be able to put those values into a list.</p>

<p>I tried using var[x] but I can only have one character at the same time and not a word right?</p>

<p>This is a duplicate of <a href="http://stackoverflow.com/questions/3873361/finding-multiple-occurrences-of-a-string-within-a-string-in-python#3873422">Finding multiple occurrences of a string within a string in Python</a></p>

<p>You can use <code>find(str, startIndex)</code> like so:</p>

<pre><code>var = "I eat breakfast."

locations = []
index = 0
while index &lt; len(var):
  index = var.find('ea', index)
  if index == -1:
    break
  locations.append(index)
  index += 2
</code></pre>

<p><code>locations</code> is a list of the indices where <code>'ea'</code> was found.</p>

python python-3.x