【发布时间】:2012-05-19 10:14:27
【问题描述】:
希伯来语在 1424 到 1514(或十六进制 0590 到 05EA)之间具有 unicode 表示。
我正在寻找正确、最有效和最 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])
其中哪些是最好的?还是我应该换一种方式?
【问题讨论】:
-
尝试对要查找的字符范围使用正则表达式。 See this question for the details.