-
Notifications
You must be signed in to change notification settings - Fork 0
/
Set Mutations.py
51 lines (34 loc) · 1.21 KB
/
Set Mutations.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
# Author: Marlon Somwaru
# Website: MarlonSomwaru.com
# Github: https://github.com/msomwaru13
# HackerRank: https://www.hackerrank.com/MarlonS
def Set_Update(set_name):
temp_set = set(map(int, input().split()))
set_name.update(temp_set)
return set_name
def Set_SymDiff_Update(set_name):
temp_set = set(map(int, input().split()))
set_name.symmetric_difference_update(temp_set)
return set_name
def Set_Diff_Update(set_name):
temp_set = set(map(int, input().split()))
set_name.difference_update(temp_set)
return set_name
def Set_Int_Update(set_name):
temp_set = set(map(int, input().split()))
set_name.intersection_update(temp_set)
return set_name
a = int(input())
a_set = set(map(int, input().split()))
Num_Ops=int(input())
for i in range(Num_Ops):
command_input=input().split()
if(command_input[0]=='intersection_update'):
Set_Int_Update(a_set)
elif(command_input[0]=='update'):
Set_Update(a_set)
elif(command_input[0]=='symmetric_difference_update'):
Set_SymDiff_Update(a_set)
elif(command_input[0]=='difference_update'):
Set_Diff_Update(a_set)
print(sum(a_set))