When it is required to display the letters that are present in the first string but not in the second string, two string inputs are taken from user. The ‘set’ is used to find the difference between the two strings.
Python comes with a datatype known as ‘set’. This ‘set’ contains elements that are unique only.
The set is useful in performing operations such as intersection, difference, union and symmetric difference.
Below is a demonstration for the same −
my_str_1 = input("Enter the first string...") my_str_2 = input("Enter the second string...") my_result = list(set(my_str_1)-set(my_str_2)) print("The letters in first string but not in second string :") for i in my_result: print(i)
Enter the first string...Jane Enter the second string...Wane The letters in first string but not in second string : J