Search code examples
pythonunicodepython-unicode

Python: Are there any libraries with all the unicode characters similar to the string library for ascii characters?


In python, the string library has methods like string.ascii_letters. Is there anything similar for Unicode characters or symbols? I haven't been able to find anything myself.

I appreciate any help! Fairly new to this type of thing so apologies if this question is dumb.


Solution

  • You can simply use the chr built-in function.

    Return the string representing a character whose Unicode code point is the integer i. For example, chr(97) returns the string 'a', while chr(8364) returns the string '€'. The valid range for the argument is from 0 through 1,114,111 (0x10FFFF in base 16). ValueError will be raised if i is outside that range.

    So you can do something like this to get a result similar to string.ascii_letters:

    ''.join(map(chr, range(1114112)))
    

    Instead, if you just want a list:

    list(map(chr, range(1114112)))