Python Practice › String Programs › Program 77
Uncommon characters of two strings
Write a Python program to build a string from the characters that appear in only one of two strings.
Input
"abcdefg", "xyzabcd"
Output
efgxyz
Approach
- Keep characters of each string that are not in the other.
Solution
s1, s2 = "abcdefg", "xyzabcd"result = [ch for ch in s1 if ch not in s2] + [ch for ch in s2 if ch not in s1]print("".join(result))Output
efgxyz
Learn the concept
New to this topic? Read the lesson, then come back.