Q:

Write a Python program to create a string from two given strings concatenating uncommon characters of the said strings

0

Write a Python program to create a string from two given strings concatenating uncommon characters of the said strings.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

def uncommon_chars_concat(s1, s2):   
     
     set1 = set(s1) 
     set2 = set(s2) 
  
     common_chars = list(set1 & set2) 
     result = [ch for ch in s1 if ch not in common_chars] + [ch for ch in s2 if ch not in common_chars] 
     return(''.join(result))

s1 = 'abcdpqr'
s2 = 'xyzabcd'
print("Original Substrings:\n",s1+"\n",s2)
print("\nAfter concatenating uncommon characters:")
print(uncommon_chars_concat(s1, s2))

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now