title: How to find and count emoticons in a string using python?
body: <p>This topic has been addressed for text based emoticons at <a href="https://stackoverflow.com/questions/18283681/regular-expressions-emoticons">link1</a>, <a href="https://stackoverflow.com/questions/10890261/how-to-match-a-emoticon-in-sentence-with-regular-expressions">link2</a>, <a href="https://stackoverflow.com/questions/14571103/capturing-emoticons-using-regular-expression-in-python">link3</a>. However, I would like to do something slightly different than matching simple emoticons. I'm sorting through tweets that contain the emoticons' icons. The following unicode information contains just such emoticons: <a href="http://www.unicode.org/charts/PDF/U1F600.pdf" rel="nofollow noreferrer">pdf</a>.</p>
  <p>Using a string with english words that also contains any of these emoticons from the <a href="http://www.unicode.org/charts/PDF/U1F600.pdf" rel="nofollow noreferrer">pdf</a>, I would like to be able to compare the number of emoticons to the number of words.</p>
  <p>The direction that I was heading down doesn't seem to be the best option and I was looking for some help. As you can see in the script below, I was just planning to do the work from the command line:</p>
  <pre><code>$cat &lt;file containing the strings with emoticons&gt; | ./emo.py
  </code></pre>
  <p>emo.py psuedo script:</p>
  <pre><code>import re
  import sys
  
  for row in sys.stdin:
      print row.decode('utf-8').encode(&quot;ascii&quot;,&quot;replace&quot;)
      #insert regex to find the emoticons
      if match:
         #do some counting using .split(&quot; &quot;)
         #print the counting
  </code></pre>
  <p>The problem that I'm running into is the decoding/encoding. I haven't found a good option for how to encode/decode the string so I can correctly find the icons. An example of the string that I want to search to find the number of words and emoticons is as follows:</p>
  <p>&quot;Smiley emoticon rocks!<img src="https://i.stack.imgur.com/hOZzk.png" alt="enter image description here" /> I like you<img src="https://i.stack.imgur.com/jccuO.png" alt="enter image description here" />.&quot;</p>
  <p>The challenge: <strong>can you make a script that counts the number of words and emoticons in this string?</strong> Notice that the emoticons are both sitting next to the words with no space in between.</p>