Python: Compare Two Lists And Update Value In List2 Based On Value In List1
I have kinda a tricky problem I want to solve. I have two lists: word = ['run', 'windless', 'marvelous'] pron = ['rVn', 'wIndl@s', 'mArv@l@s'] I want to do some processing that i
Solution 1:
words = ['run', 'windless', 'marvelous']
prons = ['rVn', 'wIndl@s', 'mArv@l@s']
for (i, word) in enumerate(words):
if "less" in word:
prons[i] = prons[i].replace("l@s", "lIs")
print(prons)
Solution 2:
Do you mean something like that?
>>> for i,w in enumerate(word):
... if 'less' in w:
... pron[i] = pron[i].replace('l@s','lIs')
...
>>> pron
['rVn', 'wIndlIs', 'mArv@l@s']
Post a Comment for "Python: Compare Two Lists And Update Value In List2 Based On Value In List1"