How to Find Letter(s) Appearing Only in One String in Python


In this example we will show how to find letters in the first string, but not in the second string.

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("Letter apperas in the first string but not in the second string: ")
for i in s:
    print(i, end="\t")

Output:

Please input the first string: apple
Please input the second string: Hello Python
Letter apperas in the first string but not in the second string: 
p	a
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments