I'm trying to do a search with regex within two lists that have similar strings, but not the same, how to fix the fault below?
Script:
import re
list1 = [
'juice',
'potato']
list2 = [
'juice;44',
'potato;55',
'apple;66']
correlation = []
for a in list1:
r = re.compile(r'\b{}\b'.format(a), re.I)
for b in list2:
if r.search(b):
pass
else:
correlation.append(b)
print(correlation)
Output:
['potato;55', 'apple;66', 'juice;44', 'apple;66']
Desired Output:
['apple;66']
Regex:

list1in each item oflist2and if e.g.'juice'isn't in'potato;55'it is added tocorrelation.Falsebefore the inner for-loop, set it in the inner loop toTrueif you found a match, after the loop add tocorrelationif flag isFalseyet.