Computer >> 컴퓨터 >  >> 프로그램 작성 >> Python

둘 이상의 목록의 합집합을 찾는 Python 프로그램?

<시간/>

Union 연산은 List1과 List 2의 모든 요소를 ​​가져와야 하고 모든 요소는 다른 세 번째 목록에 저장해야 합니다.

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]