I am beginner in learning Python and I have two lists
list1 = [\'product\',\'document\',\'light\',\'time\',\'run\']
list2 = [\'survival\',\'shop\',\'document\',\
Try:
matching_words = []
notmatching_words = list(list2) # copying the list2
for i in list1:
if i in list2:
matching_words.append(i) # appending the match
notmatching_words.remove(i) # removing the match
else:
notmatching_words.append(i) # appending the un-matched
This gives:
>>> matching_words
['document', 'run']
>>> notmatching_words
['survival', 'shop', 'product', 'light', 'time']
Or you can use the set matching:
matching_words = list (set(list1) & set(list2)) # finds elements existing in both the sets
notmatching_words = list(set(list1) ^ set(list2))