Python Program to Check Common Letters in Two Input Strings

This is a Python Program to check common letters in the two input strings.

Problem Description

The program takes two strings and checks common letters in both the strings.

Problem Solution

1. Enter two input strings and store it in separate variables.
2. Convert both of the strings into sets and find the common letters between both the sets.
3. Store the common letters in a list.
4. Use a for loop to print the letters of the list.
5. Exit.

advertisement

Program/Source Code

Here is source code of the Python Program to check common letters in the two input strings. The program output is also shown below.

s1=raw_input("Enter first string:")
s2=raw_input("Enter second string:")
a=list(set(s1)&set(s2))print("The common letters are:")for i in a:
print(i)

Program Explanation

1. User must enter two input strings and store it in separate variables.
2. Both of the strings are converted into sets and the common letters between both the sets are found using the ‘&’ operator.
3. These common letters are stored in a list.
4. A for loop is used to print the letters of the list.

advertisement

Runtime Test Cases

Case 1:
Enter first string:Hello
Enter second string:How are you
The common letters are:
H
e
o
Case 2:
Enter first string:Test string
Enter second string:checking
The common letters are:
i
e
g
n