Answer the question
In order to leave comments, you need to log in
How to compare two lists with partial match of elements?
Good afternoon, how can I compare two lists with a partial match on the elements?
trying to do so
files = ['новая папка', 'games', 'install', 'фото', 'музыка']
search = ['папка', 'фотки', 'музло']
result=list(set(search) & set(files))
print(result)
Answer the question
In order to leave comments, you need to log in
it will be crooked and not entirely correct, but there is no simple solution here, you have to take and look for semantic comparison
import re
files = ['новая папка', 'games', 'install', 'фото', 'музыка']
search = ['папка', 'фотки', 'музло']
finds = set()
chars_find = re.compile(r'\w{3}')
for file in files:
for world_search in search:
for world in chars_find.findall(world_search):
if world in file:
finds.add(file)
print(finds)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question