Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

120
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda