Set .intersection() Operation

Sort by

recency

|

446 Discussions

|

  • + 0 comments

    a = int(input()) b = set(map(int, input().split())) c = int(input()) d = set(map(int, input().split()))

    e = b.intersection(d) count = 0 for i in range(len(e)): count = count+1

    print(count)

  • + 0 comments

    n= int(input()) a= set(input().split()) b= int(input()) e = set(input().split()) r = a.intersection(e) print (len(r)) We need to perform same technique like as we do in the union method. In this method also we have taken set method and everything but at the last instead of union we have used intersection as we require the common studebts using both the papers

  • + 0 comments

    a=int(input()) n=set(map(int,input().split())) b=int(input()) c=set(map(int,input().split())) r=n.intersection(c) print(len(r))

  • + 0 comments

    n = int(input()) n1 = set(map(int,input().split())) b = int(input()) b1 = set(map(int,input().split())) both_subscribed = n1.intersection(b1) print(len(both_subscribed))

  • + 0 comments
    def stud_both_papers(a,b):
        return len(a.intersection(b))  #a&b
    
    
    
    if __name__ == '__main__':
        n = int(input())
        set1 = set(map(int,input().split()))
        b = int(input())
        set2 = set(map(int,input().split()))
        
        print(stud_both_papers(set1,set2))