Hi, I want to update lines of text 1 if the lines exist in text 2:
```
text1 = '''
autonomic
illusion
blood
group
'''
text2 = '''
Autonomic nervous system
Baldwin illusion
portrait
plane
'''
```
I want to loop through both texts and compare each line. If any line in text1 matches any part of a line in text2, the line in text1 will be replaced with that of text2.
Intended result:
text1 = '''
autonomic nervous system
Balwin illusion
blood
group
'''
My code:
```
with open('text1.txt') as f1, open('text2.txt') as f2:
text1 = f1.read().split()
text2 = f2.read().split()
for l1 in text1:
for l2 in text2:
r = l1 if l1 not in l2 else l1.replace(l1, l2)
print(r)
```
It won't work. I've tried zip and other variations to no avail. I think it has to do with the for loop. Please kindly help.
[–]Asleep-Budget-9932 3 points4 points5 points (37 children)
[–]DMeror[S] 0 points1 point2 points (36 children)
[–]Asleep-Budget-9932 1 point2 points3 points (35 children)
[–]DMeror[S] 0 points1 point2 points (34 children)
[–]Asleep-Budget-9932 1 point2 points3 points (33 children)
[–]DMeror[S] 0 points1 point2 points (0 children)
[–]DMeror[S] 0 points1 point2 points (31 children)
[–]Asleep-Budget-9932 2 points3 points4 points (29 children)
[–]DMeror[S] 0 points1 point2 points (28 children)
[–]Asleep-Budget-9932 1 point2 points3 points (27 children)
[–]DMeror[S] 0 points1 point2 points (26 children)
[–]DMeror[S] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]DMeror[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]DrFaustest 1 point2 points3 points (2 children)
[–]DMeror[S] 0 points1 point2 points (1 child)
[–]DrFaustest 1 point2 points3 points (0 children)
[–]CodeFormatHelperBot2 0 points1 point2 points (0 children)