If it matches the string then increment else continue meaning if x = ["you","me","us","then"] and y = ["hi","king","you","you","thai","you"] the code should take string you compare with all the elements in y and then increment a variable if it matches and return 3 Note: the code should not stop if it matches once with you it should search till end of the elements?

1

There are 1 best solutions below

0
On
x = ["you","me","us","then"] 
y = ["hi","king","you","you","thai","you"]

word_count = {}
for each_word in x :
   word_count[each_word] = y.count(each_word)

print(dict)
#result : {'you': 3, 'me': 0, 'us': 0, 'then': 0}

if this is not the answer you are looking for, Please explain the question by providing sample result you are expecting.