Answer the question
In order to leave comments, you need to log in
How to make searching faster in Python?
There is a tuple of tuples of row id and sentences, obtained in postgresql by a select.
Example,
data = ((1, 'Здравствуйте, я ваша тетя'), (2, 'Алял ля ля, оле леле'), (3, 'Для этой ситуации необходим VPN'))
searching_word = 'необходим'
searched_ids = []
for id, sentence in data:
if word in sentence:
searched_ids.append(id)
continue
Answer the question
In order to leave comments, you need to log in
The search must initially be done using SQL, or in general, use a separate indexer of the elasticsearch type
You can use the list generator, it works faster than a regular loop
def func(data, searching_word):
return [id for id, sentence in data if searching_word in sentence ]
result = func(((1, 'Здравствуйте, я ваша тетя'), (2, 'Алял ля ля, оле леле'), (3, 'Для этой ситуации необходим VPN')), 'необходим')
print(result) # --> [3]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question