Title:
Enter two strings, and outputs two sets of string collection.
For example: two strings received as "abc" and "bcd", returns [ 'a', 'b' , 'c', 'd']
Considerations:
1. Enter the two strings, .split () is bounded at break character string segmentation. Segmentation 'abc' available list.
Whether 2.input formatted as str () can be.
And 3. The output current, i.e. set form, and the results are sorted using sorted ().
4. The set of available and a | b or .union (), need to be taken to ensure a, b are set.
Procedure:
1. Direct calculation
str1=list(str(input("请输入第一个字符串:")))
str2=list(str(input("请输入第二个字符串:")))
print("两个字符串的并集",sorted(set(str1).union(str2)))
2. Defined Functions
def un(str1,str2):
a=set(str1)
b=set(str2)
c=sorted(a|b)
return c
str1=list(input("请输入第一个字符串:"))
str2=list(input("请输入第二个字符串:"))
print(un(str1,str2))