Set .union() Operation

Sort by

recency

|

781 Discussions

|

  • + 0 comments
    n=int(input())
    english = set(list(map(int, input().split())))
    b= int(input())
    french= set(list(map(int, input().split())))
    both = english.union(french)
    
    print(len(both))
    
  • + 0 comments
    n = int(input())
    english = set(map(int, input().split()))
    
    b = int(input())
    french = set(map(int, input().split()))
    
    
    diff = english.union(french)
    print(len(diff))
    
  • + 0 comments
    n = int(input())
    eng = set(map(int, input().split()))
    b = int(input())
    fre = set(map(int, input().split()))
    
    print(len(eng | fre))
    
  • + 0 comments

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

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

    print(count)

  • + 0 comments

    I am giving explanation to my code. First I have used n=int(input()) => for the number of students are in the english news paper and then I am setting this to the set method which is a= set(input().split()) as the numbers need to be split and I am repeating the same procedure for french paper. Later, we need to do the union method and print the length. n = int(input()) n= set(input().split()) b = int(input()) e= set(input().split()) r = n.union(e) print(len(r))