This is a Python Program to display which letters are in the first string but not in the second string.
The program takes two strings and displays which letters are in the first string but not in the second string.
1. Enter two input strings and store it in separate variables.
2. Convert both of the strings into sets and find which letters are present in the first string but not in the second string.
3. Store the letters in a list.
4. Use a for loop to print the letters of the list.
5. Exit.
Here is source code of the Python Program to display which letters are in the first string but not in the second string. The program output is also shown below.
s1=raw_input("Enter first string:") s2=raw_input("Enter second string:") a=list(set(s1)-set(s2)) print("The letters are:") for i in a: print(i)
1. User must enter two input strings and store it in separate variables.
2. Both of the strings are converted into sets and the letters which are in the first string but not in the second string are found using the ‘-‘ operator.
3. These letters are stored in a list.
4. A for loop is used to print the letters of the list.
Case 1: Enter first string:Hello Enter second string:world The letters are: H e Case 2: Enter first string:Python Enter second string:Programming language The letters are: y h t
Sanfoundry Global Education & Learning Series – Python Programs.
To practice all Python programs, here is complete set of 150+ Python Problems and Solutions.
- Apply for Python Internship
- Check Python Books
- Check Information Technology Books
- Practice Programming MCQs
- Apply for Programming Internship