How to Display Shared Letters within Two Strings in Python


In this example we will show how to accept two strings and find the letters shared by the two strings in Python.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

str1 = set(input("Please input the first string: "))
str2 = set(input("Please input the second string: "))
s = str1 & str2
print("The shared letters are: ")
for i in s:
    print(i, end="\t")

Output:

Please input the first string: Hello Python
Please input the second string: apple
The shared letters are: 
e	l
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments