[Solved] How to compare lists of words and strings, then to print full string that contains word using python? [closed]


If you want to check if a string i contains string j, you can do it using i in j. Then comes the part how do you want the output actually. What my approach was to go through the list1 and for each of them go though the list2 and check if element of list2 contains the element of list1. If contains then i checked if they are equal or not. If equal i skipped them. Otherwise i have printed the element of list2.

As @mathius indicated, my code will print the same element of list2 more than once. I didn’t handle that because to me, post maker didn’t want that. Look forward to your opinion. Here is my code:

for i in list1:
    for j in list2:
        if i in j and i != j:
            print j

11

solved How to compare lists of words and strings, then to print full string that contains word using python? [closed]