
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Concatenated string with uncommon characters in Python?
Here two strings are given, first we have to remove all the common element from the first string and uncommon characters of the second string have to be concatenated with uncommon element of first string.
Example
Input >> first string::AABCD Second string:: MNAABP Output >> CDMNP
Algorithm
Uncommonstring(s1,s2) /* s1 and s2 are two string */ Step 1: Convert both string into set st1 and st2. Step 2: use the intersection of two sets and get common characters. Step 3: now separate out characters in each string which are not common in both string. Step 4: join each character without space to get a final string.
Example code
# Concatination of two uncommon strings def uncommonstring(s1, s2): # convert both strings into set st1 = set(s1) st2 = set(s2) # take intersection of two sets to get list of common characters lst = list(st1 & st2) finallist = [i for i in s1 if i not in lst] + \ [i for i in s2 if i not in lst] print("CONCATENATED STRING IS :::", ''.join(finallist)) # Driver program if __name__ == "__main__": s1 =input("Enter the String ::") s2=input("Enter the String ::") uncommonstring(s1,s2)
Output
Enter the String ::abcde Enter the String ::bdkl CONCATEATED STRINGIS ::: acekl
- Related Questions & Answers
- Concatenated string with uncommon characters in Python program
- Maximum Length of a Concatenated String with Unique Characters in C++
- Program to find length of concatenated string of unique characters in Python?
- Find the uncommon values concatenated from both the strings in Java
- How to print concatenated string in Python?
- Find uncommon characters of the two strings in C++
- C++ program to find uncommon characters in two given strings
- Find uncommon characters of the two strings in C++ Program
- Finding and returning uncommon characters between two strings in JavaScript
- Maximum Consecutive Zeroes in Concatenated Binary String in C++
- Concatenated Words in C++
- Longest string with two distinct characters in JavaScript
- Iterate over characters of a string in Python
- Extract only characters from given string in Python
- Program to swap string characters pairwise in Python
Advertisements