Two lists were created through several operations.
a = ["Cat", "Dog", "Pigeon", "Eagle", "Camel"]
b = ["Tiger", "Bat", "Whale", "Snake", "Bear"]
I'm trying to replace a string using this list. (a) using a list to search for a word and (b) replacing it with a list. The order can be substituted in the same order as each list.
Each word is replaced with cat -> Tiger / Dog ->Bat / Pigeon -> Whale / Eagle -> Snake /Camel -> Bear in list order.
text = """
Cats and dogs live in our village. There are also pigeons and eagles.
There are no camels.
Cats and dogs live in our village. There are also pigeons and eagles.
There are no camels.
Cats and dogs live in our village. There are also pigeons and eagles.
There are no camels.
.....
"""
The desired result is
text = """
Tigers and bats live in our village. There are also whales and snakes.
There are no bears.
Tigers and bats live in our village. There are also whales and snakes.
There are no bears.
Tigers and bats live in our village. There are also whales and snakes.
There are no bears.
.....
"""
I've tried a number of other things besides this one, but to no avail. Help
new_text = []
num = 1
num1 = 1
for line in text.split('\n'):
text = text.replace(a[num], b[num1])
new_text.append(text)
num += 1
num1 += 1