집합 이론에서 집합 A의 보수는 A에 없는 요소를 나타냅니다. 집합 B에 대한 A의 상대 보수(집합 A와 B의 차라고도 함)를 나타냅니다. 여기에서 이 원칙을 적용합니다. 파이썬에는 차이점 기능이 있습니다.
알고리즘
Step 1 : first we create two user input list. A & B Step 2 : Insert A and B to a set. Step 3 : for finding the missing values of first list we apply difference function, difference of B from A. Step 4 : for finding the Additional values of first list we apply difference function, difference of A from B. Step 5 : Same procedure apply for Second list also.
예시 코드
#To find the missing and additional elements A=list() B=list() n1=int(input("Enter the size of the First List ::")) n2=int(input("Enter the size of the second List ::")) print("Enter the Element of first List ::") for i in range(int(n1)): k=int(input("")) A.append(k) print("Enter the Element of second List ::") for j in range(int(n2)): k1=int(input("")) B.append(k1) # prints the missing and additional elements in first list print("Missing values in first list:", (set(B).difference(A))) print("Additional values in first list:", (set(A).difference(B))) # prints the missing and additional elements in second list print("Missing values in second list:", (set(A).difference(B))) print("Additional values in second list:", (set(B).difference(A)))
출력
Enter the size of the First List :: 6 Enter the size of the second List :: 5 Enter the Element of first List :: 1 2 3 4 5 6 Enter the Element of second List :: 4 5 6 7 8 Missing values in first list: {7, 8} Additional values in first list: {1, 2, 3} Missing values in second list: {1, 2, 3} Additional values in second list: {7, 8}