检查字符串的正确方法有希伯来字符

iTa*_*ayb 1 python ord

希伯来语在1424年至1514年(或十六进制0590至05EA)之间具有unicode表示.

我正在寻找合适,最有效和最pythonic的方法来实现这一目标.

首先我想出了这个:

for c in s:
    if ord(c) >= 1424 and ord(c) <= 1514:
        return True
return False
Run Code Online (Sandbox Code Playgroud)

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

return any(map(lambda c: (ord(c) >= 1424 and ord(c) <= 1514), s))
Run Code Online (Sandbox Code Playgroud)

有可能:

return any([(ord(c) >= 1424 and ord(c) <= 1514) for c in s])
Run Code Online (Sandbox Code Playgroud)

哪些是最好的?或者我应该做不同的事情?

MRA*_*RAB 16

你可以这样做:

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