We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Sets
- Set .union() Operation
- Discussions
Set .union() Operation
Set .union() Operation
Sort by
recency
|
778 Discussions
|
Please Login in order to post a comment
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)
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))
a=int(input()) n=set(map(int,input().split())) b=int(input()) e=set(map(int,input().split())) r=n.union(e) print(len(r))
a=int(input()) n=set(map(int,input().split())) b=int(input()) e=set(map(int,input().split())) r=n.union(e) print(len(r))
n=int(input()) a=set(input().split()) n1=int(input()) a1=set(input().split()) print(len(a | a1))