How to merge two strings by letters erasing duplicates in Python

3 Answers

0 votes
str1 = "python java c python c++ java java"
str2 = "python c++ c# javascript java c c php"

merge_str = ' '.join(set(str1 + str2))

print(merge_str)



 
'''
run:
 
o   h # i s n y p r c a t + v j

'''

 



answered Sep 23, 2022 by avibootz
0 votes
str1 = "python java c python c++ java java"
str2 = "python c++ c# javascript java c c php"

merge_str = ' '.join(sorted(set(str1 + str2)))

print(merge_str)



 
'''
run:
 
  # + a c h i j n o p r s t v y

'''

 



answered Sep 23, 2022 by avibootz
0 votes
str1 = "python java c python c++ java java"
str2 = "python c++ c# javascript java c c php"

merge_str = ' '.join(sorted(set(str1).union(str2)))

print(merge_str)



 
'''
run:
 
  # + a c h i j n o p r s t v y

'''

 



answered Sep 23, 2022 by avibootz
...