Convert each string to a set of characters, then find the intersection.
word1 = "hello"
word2 = "world"
chars1 = set(word1) # {'h', 'e', 'l', 'o'}
chars2 = set(word2) # {'w', 'o', 'r', 'l', 'd'}
common = chars1 & chars2 # {'l', 'o'}
The intersection gives you characters present in both strings. The length of that intersection is your answer.
No nested loops. No manual tracking. Just set operations.