简体   繁体   中英

Get a list of all Greek unicode characters

I would like to know how to obtain a list of all Greek characters (upper and lowercase letters). I know how to find specific characters ( unicodedata.lookup(name) ), but I want all upper and lowercase letters.

Is there any way to do this?

The Unicode standard defines the range 0x370 through 0x3ff (inclusive) as Greek and Coptic symbols. The symbols that are exclusively Coptic (ie not shared with Greek) are 0x3e2 through 0x3ef (inclusive).

You can thus iterate through the two ranges 0x370-0x3e1 (inclusive) and 0x3f0-0x3ff (inclusive) to get all the Greek symbols, and use str.isalpha() to test each to see if it's a letter. For example:

from itertools import chain
greek_codes   = chain(range(0x370, 0x3e2), range(0x3f0, 0x400))
greek_symbols = (chr(c) for c in greek_codes)
greek_letters = [c for c in greek_symbols if c.isalpha()]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM