-1
I am trying to search for elements of the A list in List B and replace it with another value if this element is found. How can I do this?
A = ["Leao" , "Lobo" , "Largarto"]
B = ["Cachorro" , "Leao" , "Cobra" , "Girafa" , "Lobo" , "Largarto"]
Replace element of A in B by the word "Manga" and the result would be
C = ["Cachorro" , "Manga" , "Cobra" , "Girafa" , "Manga" , "Manga"]
Searching I only managed to find this code, but then I would have to every time write what I need to replace:
B = [item.replace("Leao", "Manga") for item in B]
Thank you very much, it worked perfectly.
– mixelsan