How to join two sets in one line without using “|”

前端 未结 8 1058
闹比i
闹比i 2020-12-23 00:21

Assume that S and T are assigned sets. Without using the join operator |, how can I find the union of the two sets? This, for example,

8条回答
  •  别那么骄傲
    2020-12-23 01:01

    Suppose you have 2 lists

     A = [1,2,3,4]
     B = [3,4,5,6]
    

    so you can find A Union B as follow

     union = set(A).union(set(B))
    

    also if you want to find intersection and non-intersection you do that as follow

     intersection = set(A).intersection(set(B))
     non_intersection = union - intersection
    

提交回复
热议问题