[Python] How do I count letters in a string?

Discussão em 'Python' iniciado por Stack, Junho 11, 2025.

  1. Stack

    Stack Membro Participativo

    Say I have a UTF-8 str, for example

    my_str = "नमस्ते" # ['न', 'म', 'स', '्', 'त', 'े']


    how do I find how many letters it contains? len(my_str) returns 6, which is how many Unicode code points it contains. It's actually 4 letters long.

    And bonus question: some languages define digraphs as a single letter (for example "Dh" is the 6th letter of the modern Albanian alphabet), how can I handle that edge case?

    Continue reading...

Compartilhe esta Página