- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program that Displays which Letters are in the First String but not in the Second
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
- Two strings are taken as input from the user.
- They are converted to a set, and their difference is computed.
- This difference is converted to a list.
- This value is assigned to a variable.
- This is iterated over, and displayed on the console.
- Python Program that Displays which Letters are in the Two Strings but not in Both
- Python Program that Displays which Letters are Present in Both the Strings
- Find the character in first string that is present at minimum index in second string in Python
- Count elements present in first array but not in second in C++
- Program to find all words which share same first letters in Python
- Find elements which are present in first array and not in second in C++
- Python program to calculate the number of digits and letters in a string
- Check whether second string can be formed from characters of first string in Python
- Get first three letters from every string in C#
- Program to check the string is repeating string or not in Python