Skip to main content

Posts

Showing posts with the label For loop

iterate and compare two lists in python, if contains string from the other list, pop item

I'm trying to comparing two lists ( mama and filterkeywords in the code shown), and remove values from the first list depending on the second. I have this code: occurenceList = [] title = ['SL C ','FS D ','FS H','FS F','FS D','SL C','SL F','FS H','SL H','SL D'] mama = ['slow cat Sas','fast dog PoP','fast hen Luke','fast fish Lee','fast dog joe','slow cat yan','slow fish ben','Fast hen Tim','Slow hen Jen','slow dog moe'] filterkeywords = ['hen','dog','fish','Fish'] print(" ") for text in mama: for words in filterkeywords: if words in text: animal = (mama.index(text)) print("index: ", animal, ' | ', mama[animal], " | Word Found: ", words) title.pop(animal) mama.pop(animal) print(" ") for items i...