title: finding needle in haystack, what is a better solution?
body: <p>so given "needle" and "there is a needle in this but not thisneedle haystack"</p>
  
  <p>I wrote</p>
  
  <pre><code>def find_needle(n,h):
      count = 0
      words = h.split(" ")
      for word in words:
          if word == n:
              count += 1
      return count
  </code></pre>
  
  <p>This is O(n) but wondering if there is a better approach? maybe not by using split at all?</p>
  
  <p>How would you write tests for this case to check that it handles all edge cases?</p>