- Trending Categories
- Data Structure
- Operating System
- C Programming
- 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 Present in Both the Strings
When it is required to display the letters common to two strings, the ‘set’ method can be used.
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 −
string_1 = 'hey' string_2 = 'jane' print("The first string is :") print(string_1) print("The second string is :") print(string_2) my_result = list(set(string_1)|set(string_2)) print("The letters are : ") for i in my_result: print(i)
The first string is : hey The second string is : jane The letters are : a y j h e n
- Two strings are defined, and are displayed on the console.
- The ‘set’ is used on both these strings, along with the ‘|’ operator.
- This operation’s data is assigned to a variable. It is then displayed as output 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 in the First String but not in the Second
- Python program to remove words that are common in two Strings
- Python program to accept the strings which contains all vowels
- Program to find number of subsequence that are present inside word list in python
- Python - Find all the strings that are substrings to the given list of strings
- How to match two strings that are present in one line with grep in Linux?
- Program to find all words which share same first letters in Python
- Program to find the length of the longest, that can be made using given letters in Python
- Count of words that are present in all the given sentences in C++
- Java program to accept the strings which contain all vowels
- Find the uncommon values concatenated from both the strings in Java
- Program to check three consecutive odds are present or not in Python