<\/span><\/h2>\n\n\n\n.intersection()<\/strong><\/p>\n\n\n\nThe .intersection()<\/em> operator returns the intersection of a set and the set of elements in an iterable.
Sometimes, the &<\/em> operator is used in place of the .intersection()<\/em> operator, but it only operates on the set of elements in set<\/em>.
The set is immutable to the .intersection()<\/em> operation (or &<\/em> operation).<\/p>\n\n\n\n>>> s = set(\"Hacker\")\n>>> print s.intersection(\"Rank\")\nset(['a', 'k'])\n\n>>> print s.intersection(set(['R', 'a', 'n', 'k']))\nset(['a', 'k'])\n\n>>> print s.intersection(['R', 'a', 'n', 'k'])\nset(['a', 'k'])\n\n>>> print s.intersection(enumerate(['R', 'a', 'n', 'k']))\nset([])\n\n>>> print s.intersection({\"Rank\":1})\nset([])\n\n>>> s & set(\"Rank\")\nset(['a', 'k'])<\/code><\/pre>\n\n\n\n<\/span>Task<\/strong><\/span><\/h2>\n\n\n\nThe students of District College have subscriptions to English<\/em> and French<\/em> newspapers. Some students have subscribed only to English<\/em>, some have subscribed only to French<\/em>, and some have subscribed to both newspapers.<\/p>\n\n\n\nYou are given two sets of student roll numbers. One set has subscribed to the English<\/em> newspaper, one set has subscribed to the French<\/em> newspaper. Your task is to find the total number of students who have subscribed to both<\/em> newspapers.<\/p>\n\n\n\n<\/span>Input Format<\/strong><\/span><\/h2>\n\n\n\nThe first line contains n<\/em><\/strong>, the number of students who have subscribed to the English<\/em> newspaper.
The second line contains n<\/em><\/strong> space separated roll numbers of those students.
The third line contains b<\/em><\/strong>, the number of students who have subscribed to the French<\/em> newspaper.
The fourth line contains b<\/em><\/strong> space separated roll numbers of those students.<\/p>\n\n\n\n<\/span>Constraints<\/strong><\/span><\/h2>\n\n\n\n- 0 < Total number of students in college<\/em> < 1000<\/strong><\/li><\/ul>\n\n\n\n
<\/span>Output Format<\/strong><\/span><\/h2>\n\n\n\nOutput the total number of students who have subscriptions to both<\/strong> English<\/em> and French<\/em> newspapers.<\/p>\n\n\n\nSample Input<\/strong><\/p>\n\n\n\n9\n1 2 3 4 5 6 7 8 9\n9\n10 1 2 3 11 21 55 6 8<\/code><\/pre>\n\n\n\nSample Output<\/strong><\/p>\n\n\n\n5<\/code><\/pre>\n\n\n\nExplanation<\/strong><\/p>\n\n\n\nThe roll numbers of students who have both<\/em> subscriptions:
1, 2, 3, 6<\/strong> and 8<\/strong>.
Hence, the total is 5<\/strong> students.<\/p>\n\n\n\n<\/span>Solution – Set.intersection() Operation in Python<\/strong><\/span><\/h2>\n\n\n\n# Enter your code here. Read input from STDIN. Print output to STDOUT\n_ = int(input())\nSET_N = set(map(int, input().split()))\n\n_ = int(input())\nSET_B = set(map(int, input().split()))\n\nprint(len(SET_N & SET_B))<\/pre>\n\n\n\n