Here's the solution:
def count_common_chars(word1, word2):
chars1 = set(word1)
chars2 = set(word2)
common = chars1 & chars2
return len(common)
Or as a one-liner:
def count_common_chars(word1, word2):
return len(set(word1) & set(word2))
Time: where and are the string lengths. Space: for the smaller character set.