title: Fast transliteration for Arabic Text with Python
body: <p>I always work on Arabic text files and to avoid problems with encoding I transliterate Arabic characters into English according to Buckwalter's scheme (http://www.qamus.org/transliteration.htm)</p>
  
  <p>Here is my code to do so but it's very SLOW even with small files like 400 kb. Ideas to make it faster? </p>
  
  <p>Thanks</p>
  
  <pre><code>     def transliterate(file):
            data = open(file).read()
            buckArab = {"'":"ء", "|":"آ", "?":"أ", "&amp;":"ؤ", "&lt;":"إ", "}":"ئ", "A":"ا", "b":"ب", "p":"ة", "t":"ت", "v":"ث", "g":"ج", "H":"ح", "x":"خ", "d":"د", "*":"ذ", "r":"ر", "z":"ز", "s":"س", "$":"ش", "S":"ص", "D":"ض", "T":"ط", "Z":"ظ", "E":"ع", "G":"غ", "_":"ـ", "f":"ف", "q":"ق", "k":"ك", "l":"ل", "m":"م", "n":"ن", "h":"ه", "w":"و", "Y":"ى", "y":"ي", "F":"ً", "N":"ٌ", "K":"ٍ", "~":"ّ", "o":"ْ", "u":"ُ", "a":"َ", "i":"ِ"}    
            for char in data: 
                 for k, v in arabBuck.iteritems():
                       data = data.replace(k,v)                 
        return data
  </code></pre>