How to Display Letters within Two Strings in Python


In this example, let’s see how to display those letters included in two strings.

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: apple
Please input the second string: Python
The shared letters are: 
h	t	y	a	l	o	p	n	e	P
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments