Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!