Set.difference() | HackerRank Solution

admin
By -
0
 Here we have to  use difference operation on sets, this easy and similar our two problem, intersection() and union() once  you  can se syntax are same just only we have to use difference which checks both set elements and return with elements which not present in second set and only on set 1 
The tool .difference() returns a set with all the elements from the set that are not in an iterable.

" - "
or
set1.difference(set2)





Code:
n = int(input())
s1 = set(map(int, input().split()[:n]))
b = int(input())
s2 = set(map(int, input().split()[:b]))
#print(len(s1-s2))
print(len(s1.difference(s2)))




Post a Comment

0Comments

Please Select Embedded Mode To show the Comment System.*