logo

파이썬 세트 | 차이점()

Python에서 두 세트의 차이는 두 세트의 요소 수 간의 차이와 같습니다. Difference() 함수는 두 집합의 차이인 집합을 반환합니다. 두 세트 A와 B의 차이점이 무엇인지 알아 보겠습니다. 그러면 (세트 A – 세트 B)는 세트 A에는 있지만 B에는 없는 요소가 되고 (세트 B – 세트 A)는 존재하는 요소가 됩니다. B세트에는 있지만 A세트에는 없습니다.

예:



set A = {10, 20, 30, 40, 80} set B = {100, 30, 80, 40, 60} set A - set B = {10, 20} set B - set A = {100, 60} Explanation: A - B is equal to the elements present in A but not in B B - A is equal to the elements present in B but not in A>

다음 차이 집합 함수의 벤 다이어그램을 살펴보겠습니다. 통사론:

 set_A.difference(set_B) for (A - B) set_B.difference(set_A) for (B - A)>

이 프로그램에서는 두 세트 set_A와 set_B 사이의 차이점을 두 가지 방법으로 모두 알아내려고 노력할 것입니다.

파이썬3








# Python code to get the difference between two sets> # using difference() between set A and set B> # Driver Code> A>=> {>10>,>20>,>30>,>40>,>80>}> B>=> {>100>,>30>,>80>,>40>,>60>}> print> (A.difference(B))> print> (B.difference(A))>

numpy 표준편차

>

>

스프링 부트
산출:

{10, 20} {100, 60}>

– 연산자를 사용하여 두 집합 간의 차이를 찾을 수도 있습니다.

파이썬3




# Python code to get the difference between two sets> # using difference() between set A and set B> # Driver Code> A>=> {>10>,>20>,>30>,>40>,>80>}> B>=> {>100>,>30>,>80>,>40>,>60>}> print> (A>-> B)> print> (B>-> A)>

>

>

산출:

{10, 20} {100, 60}>

동일한 집합이 있으면 null 집합이 반환됩니다.

파이썬3


자바 int를 char로



# Python code to get the difference between two sets> # using difference() between set A and set B> # Driver Code> A>=> {>10>,>20>,>30>,>40>,>80>}> B>=> {>10>,>20>,>30>,>40>,>80>,>100>}> print> (A>-> B)>

>

>

산출:

set()>