python - 检查字符串是否包含希伯来字符的正确方法

标签 python ord

希伯来语的 unicode 表示介于 1424 和 1514 之间(或十六进制 0590 到 05EA)。

我正在寻找实现这一目标的正确、最有效和最 pythonic 的方法。

首先我想到了这个:

for c in s:
    if ord(c) >= 1424 and ord(c) <= 1514:
        return True
return False

然后我带来了一个更优雅的实现:

return any(map(lambda c: (ord(c) >= 1424 and ord(c) <= 1514), s))

也许:

return any([(ord(c) >= 1424 and ord(c) <= 1514) for c in s])

哪些是最好的?或者我应该采取不同的方式?

最佳答案

你可以这样做:

# Python 3.
return any("\u0590" <= c <= "\u05EA" for c in s)
# Python 2.
return any(u"\u0590" <= c <= u"\u05EA" for c in s)

关于python - 检查字符串是否包含希伯来字符的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10664254/

相关文章:

PHP 函数 chr 和 ord 与特殊字符

unicode - 如何在 elisp 中获取字符的代码点(以及其他方式)?

Python 3.4 : Lists stored in a file - Iterating over characters instead of list items

rust - 如何为结构实现 Ord?

python - 如何让 Keras 在 Anaconda 中使用 Tensorflow 后端?

python - 创建一个新的数据框,将每行的 k 个副本附加到自身

python - 为什么从 Python 2 移植到 Python 3 时 ord() 会失败?

python - lambdaify 包含 UndefinedFunction 的 Derivative 的 sympy 表达式

python - 基于文本的 rpg 索引超出范围错误