title: Unicode encoding, .txt and Arabic (Right-to-Left) script
body: <p>I wanted to create a histogram of word counts in a large sample by building a dictionary, then to print the most common words with their count, hence basically printing few key/value pairs.</p>
  
  <p>However, many of the words were not in latin alphabet, so I did:</p>
  
  <pre><code>       try: 
             print key, word_dict[key]
         except: 
             print key.encode('utf-8'), word_dict[key],
  </code></pre>
  
  <p>When the results are printed directly into command-line interface, the non-latin Alphabet words are just unreadable, but the key/value order is maintained.</p>
  
  <p>However, when I print the results into a .txt file, Arabic words are readable, the key/value pairs corresponding to such words seem to be printed in reverse order: value/key. Chinese characters however are printer in the correct order: key/value.</p>
  
  <p>So I wonder is .txt so "smart" that it recognizes Arabic and prints in the Right-to-Left order? And moreover, what can I do to maintain the order of key/value I want?</p>