Comparing Strings
Question: Does there exist any inbuilt function in python than can return number of
mathching characters in two strings,for example:

INPUT:

    
    
       TICK TOCK
       CAT DOG
       APPLE APPLES
    

OUTPUT:

    
    
     3
     0
     5
    

The words "TICK" and "TOCK" have a score of 3, since three characters (T, C,
K) are the same. Similarly, "CAT" and "DOG" score 0, since no letters match.

I am a new bie in python so please help me with examples.


Answer: Here's a version using list comprehensions:

    
    
    [x == y for (x, y) in zip("TICK", "TOCK")].count(True)
    

Or, shorter (using `operator`):

    
    
    import operator
    map(operator.eq, "TICK", "TOCK").count(True)
    

According to @Kabie, `<expr>.count(True)` can be replaced by `sum(<expr>)` in
both versions.

