Given two lists, I want to compare list1 and list2, and replace it within list1, and add brackets.
str1 = "red man juice"
str2 = "the red man drank the juice"
one_lst = ['red','man','juice']
lst1 = ['the','red','man','drank','the','juice']
expected output:
lst1 = ['the','[red]','[man]','drank','the','[juice]']
What I tried so far:
lst1 = list(str1.split())
for i in range(0,len(lst1)):
for j in range(0,len(one_lst)):
if one_lst[j] == lst1[i]:
str1 = str1.replace(lst1[i],'{}').format(*one_lst)
lst1 = list(str1.split())
print(lst1)
I'm able to replace it, but just without brackets.
Thanks for the help!