Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
JavaScript vs Python emoji length

I have a complex algorithm, one module is written in Python and another in JavaScript.

At some point these modules calculate string length.

The problem is when the text contains emojis, Python and JS give different results.

Example:

  • '👀' Python len: 1 ; JS len: 2
  • '👍🏾' Python len: 2 ; JS len: 4

The JS's length is more convenient in my case. Is there a way to make Python3 calculate the emoji's length as JS does?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here's the Python function to calculate string length that can contain emoji. It returns the same result as JS:

def jslen(string):
    return int(len(string.encode(encoding='utf_16_le'))/2)

Thank you @snakecharmerb for your hint!

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda