在Python程序中找到两个或多个列表的并集?
联合运算意味着,我们必须从List1和List2中获取所有元素,并将所有元素存储在另一个第三列表中。
List1::[1,2,3] List2::[4,5,6] List3::[1,2,3,4,5,6]
算法
Step 1: Input two lists. Step 2: for union operation we just use + operator.
范例程式码
# UNION OPERATION
A=list()
B=list()
n=int(input("Enter the size of the List ::"))
print("Enter the Element of first list::")
for i in range(int(n)):
k=int(input(""))
A.append(k)
print("Enter the Element of second list::")
for i in range(int(n)):
k=int(input(""))
B.append(k)
C = A + B
print("THE FINAL LIST IS ::>",C)输出结果
Enter the size of the List ::4 Enter the Element of first list:: 23 11 22 33 Enter the Element of second list:: 33 22 67 45 THE FINAL LIST IS ::> [23, 11, 22, 33, 33, 22, 67, 45]
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短