Fast transliteration for Arabic Text with Python

前端 未结 5 1111
难免孤独
难免孤独 2021-02-06 09:14

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/tra

5条回答
  •  耶瑟儿~
    2021-02-06 09:44

    You're redoing the same work for every character. When you do data = data.replace(k, v), that replaces all occurrences of the given character in the entire file. But you do this over and over in a loop, when you only need to do it once for each transliteration pair. Just remove your outermost loop and it should speed your code up immensely.

    If you need to optimize it more you could look at the string translate method. I'm not sure how that is performance-wise.

提交回复
热议问题