How to get the number of characters that two strings have in common in Python

1 Answer

0 votes
def common_characters_count(str1, str2):
    return len(set(str1) & set(str2))

str1 = "abcdefg";
str2 = "xayzgoe"

print(common_characters_count(str1, str2))  



'''
run:
 
3
 
'''

 



answered Mar 19 by avibootz
edited Mar 20 by avibootz
...