Search code examples
pythonunicodepython-module-unicodedata

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?


Solution

  • The Unicode standard defines the range 0x370 through 0x3ff (inclusive) as Greek and Coptic symbols. The symbols that are exclusively Coptic (i.e. 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()]