使用Python将阿拉伯语单词数字与字典中的相应数字相匹配

时间:2018-02-27 18:50:25

标签: python dictionary character-encoding

我正在尝试将阿拉伯数字与数字匹配,但它不起作用。如果它尝试相同的方法,但没有阿拉伯字符,它可以很好地工作。

<div class="row">
  <div class="cell">
    <div class="cell">A</div>
  </div>
  <div class="cell">
    <div class="cell">B1</div>
    <div class="cell">B2</div>
    <div class="cell">B3</div>
  </div>
  <div class="cell">
    <div class="cell">C1</div>
    <div class="cell">Very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very very long text</div>
    <div class="cell">C3</div>
  </div>
</div>

输出为def Replace(text, wordDict): for key in wordDict: text = text.replace(key, wordDict[key]) return text singular = { "واحد" :"1", "اثنان" :"2", "ثلاتة" :"3" } s="ثلاثة" s=Replace(s,singular) print(s) ,但它应为3,这意味着未执行替换操作。 有什么想法吗?

1 个答案:

答案 0 :(得分:2)

如果使用特殊字符,则应使用Unicode字符串。以下代码显示String

3

阅读more about Unicode in Python