[Python] Python 3 Word Count by Unicode Language

Discussão em 'Python' iniciado por Stack, Agosto 27, 2025.

  1. Stack

    Stack Membro Participativo

    I have texts that contain multiple languages in them. I want a word count that only records the words that occur with the Greek unicode character set using Python 3. Something like:

    wordCount = 0
    theText = open(file.txt, 'r')
    for word in theText.split():
    if GreekUnicodeCheck(word):
    wordCount += 1
    print(wordCount)


    I have considered checking if a Greek letter is in every word like so:

    wordCount = 0
    theText = open(file.txt, 'r')
    greekChars = ['α', 'β', 'γ', 'δ', 'ε', ...]
    for word in theText.split():
    if any(letter in word for letter in greekChars):
    wordCount += 1
    print(wordCount)


    I think that should work, but the character set becomes quite large when you account for all the combinations of capitalization, diacritic marks, etc. (I'm working with Classical Greek). Is there a more elegant solution?

    Continue reading...

Compartilhe esta Página