title: In Python, how to check if words in a string are keys in a dictionary?
body: <p>For a class I am talking the twitter sentiment analysis problem. I have looked at the other questions on the site and they don't help for my particular issue.</p>
  
  <p>I am given a string that is one tweet with its letters changed so that they are all in lowercase. For example, </p>
  
  <pre><code>'after 23 years i still love this place. (@ tel aviv kosher pizza) http://t.co/jklp0uj'
  </code></pre>
  
  <p>as well as a dictionary of words where the key is the word and the value is the value for the sentiment for that word. To be more specific, a key can be a single word (such as 'hello'), more than one word separated by a space (such as 'yellow hornet'), or a hyphenated compound word (such as '2-dimensional'), or a number (such as '365').</p>
  
  <p>I need to find the sentiment of the tweet by adding the sentiments for every eligible word and dividing by the number of eligible words (by eligible word, I mean word that is in the dictionary). I'm not sure what's the best way to go about checking if a tweet has a word in the dictionary.</p>
  
  <hr>
  
  <p>I tried using the "key in string" convention with looping through all the keys, but this was problematic because there are a lot of keys and word-in-words would be counted (e.g. eradicate counts cat, ate, era, etc. as well)</p>
  
  <p>I then tried using .split(' ') and looping through the elements of the resultant list but I ran into problems because of punctuation and keys which are two words.</p>
  
  <p>Anyone have any ideas on how I can more suitably tackle this?</p>
  
  <p>For example: using the example above, still : -0.625, love : 0.625, every other word is not in the dictionary.  so this should return (-0.625 + 0.625)/2 = 0.</p>