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

165
Vistas
Fast way to categorize a list

I'm trying to do the following in either python or javascript (whichever is faster):

  1. Take as inputs i) a string, ii) an ordered list of lookups, and iii) a list of categories that correspond 1:1 with [ii]
  2. Find the first element of [ii] that exists in [i]. In other words, if [i] is "tomato", I want to find the first element of [ii] that exists as a substring of [i]
  3. return the corresponding element of [iii]

Today I'm doing something like this:

for element in [ii]:
   check if [ii] is a substring of [i]
   if yes, then:
      store the corresponding category from [iii]
      end loop
   else:
      continue loop

The problem with this is that when I'm doing this over a lot of strings (e.g., a list of things in item [i]) it takes a super long time.

Does anyone have an algorithm / approach that can make this faster?

about 4 years ago · Juan Pablo Isaza
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