To create a Chinese alphabet list in Python, you can use the ord()
function to get the Unicode code point of each character and store it in a list. Here's an example:
main.py148 chars6 lines
In this example, we first specify the encoding of the Python file using the coding
declaration at the top of the file, which tells Python that the file is encoded in UTF-8.
Next, we create an empty list called chinese_alphabet
. We then loop through every character in the Chinese range of Unicode code points, which starts at code point 19968 (ord('一')
) and ends at code point 40869 (not inclusive).
For each code point, we use the chr()
function to convert the code point back into a character and append it to the chinese_alphabet
list.
Finally, we print out the entire chinese_alphabet
list to verify that all of the characters have been added correctly.
Note that this method does not include any non-standard Chinese characters that may be used in names, brands, or other contexts.
gistlibby LogSnag