-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathset_symm_diff.py
69 lines (48 loc) · 2.28 KB
/
set_symm_diff.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
A^B.png.symmetric_difference()
.symmetric_difference() operator returns a set with all elements that are in set and iterable but not both.
Sometimes '^' operator is used in place of .symmetric_difference() operator but it operates only on the set of elements in set.
Set is immutable to .symmetricdifference() operation (or '^' operation).
>>> s = set("Hacker")
>>> print s.symmetric_difference("Rank")
set(['c', 'e', 'H', 'n', 'R', 'r'])
>>> print s.symmetric_difference(set(['R', 'a', 'n', 'k']))
set(['c', 'e', 'H', 'n', 'R', 'r'])
>>> print s.symmetric_difference(['R', 'a', 'n', 'k'])
set(['c', 'e', 'H', 'n', 'R', 'r'])
>>> print s.symmetric_difference(enumerate(['R', 'a', 'n', 'k']))
set(['a', 'c', 'e', 'H', (0, 'R'), 'r', (2, 'n'), 'k', (1, 'a'), (3, 'k')])
>>> print s.symmetric_difference({"Rank":1})
set(['a', 'c', 'e', 'H', 'k', 'Rank', 'r'])
>>> s ^ set("Rank")
set(['c', 'e', 'H', 'n', 'R', 'r'])
Task
Students of District College have subscription of English and French newspapers. Some students have subscribed to only English, some have subscribed to only French and some have subscribed to both newspapers.
You are given two sets of roll numbers of students, who have subscribed to English and French newspapers. Your task is to find total number of students who have subscribed to English or French newspapers but not both.
Input Format
First line contains, number of students who have subscribed to English newspaper.
Second line contains, space separated list of roll numbers of students, who have subscribed to English newspaper.
Third line contains, number of students who have subscribed to French newspaper.
Fourth line contains, space separated list of roll numbers of students, who have subscribed to French newspaper.
Constraints
0<Total number of students in college<1000
Output Format
Output total number of students who have subscriptions of English or French newspaper but not both.
Sample Input
9
1 2 3 4 5 6 7 8 9
9
10 1 2 3 11 21 55 6 8
Sample Output
8
Explanation
Roll numbers of students who have subscriptions of English or French newspaper but not both:
4, 5, 7, 9, 10, 11, 21 and 55.
Hence, total is 8 students
"""
e = input()
el = set(map(int,raw_input().split()))
f = input()
fl = set(map(int,raw_input().split()))
diff = el.symmetric_difference(fl)
print len(diff)