Count of Common Characters in the Strings - python - Spicy Coders

Recent

Monday, July 31, 2017

Count of Common Characters in the Strings - python

Two string values S1 and S2 are passed as input. The program must print the count of common characters in the strings S1 and S2. 

Input Format: First line will contain the value of string S1 Second line will contain the value of string S2

Output Format: First line will contain the count of common characters. 

Boundary Conditions: Length of S1 and S2 is from 3 to 100. 

Sample Input/Output: 
Example 1: 
Input: 
china 
india 
Output: 

Explanation: The common characters are i,n,a 

Example 2: 
Input: 
energy
every
Output:

Explanation: The common characters are e,e,r,y

Source Code:

from collections import Counter
s1,s2=input(),input()
l=Counter(s1)&Counter(s2)

print(sum(l.values()))

1 comment:

  1. What is the programes for above without reputation of letters

    ReplyDelete