6
通常希望列出给定Unicode类别中的所有字符。例如:高效地列出给定Unicode类别中的所有字符
- List all Unicode whitespace,How can I get all whitespaces in UTF-8 in Python?
- Characters with the property
Alphabetic
,能够产生该列表通过遍历所有Unicode码点和测试所需的类别(Python 3中):
[c for c in map(chr, range(0x110000)) if unicodedata.category(c) in ('Ll',)]
或使用正则表达式,
re.findall(r'\s', ''.join(map(chr, range(0x110000))))
但是这些方法很慢。有没有办法查找类别中的字符列表,而无需遍历所有的字符?
Perl的相关问题:How do I get a list of all Unicode characters that have a given property?
应该用map() –
@ m.kocikowski中的unichr()替换chr():除非您使用的是Python 3,问题的OP明确表示(否则在Python 2中会失败)。 –