Python compare two strings and check how many chars they have in common
from collections import Counter def shared_chars(s1, s2): return sum((Counter(s1) & Counter(s2)).values()) print(shared_chars('car', 'carts'))
Output
3
from collections import Counter def shared_chars(s1, s2): return sum((Counter(s1) & Counter(s2)).values()) print(shared_chars('car', 'carts'))
3