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 Mutations
- Discussions
Set Mutations
Set Mutations
Sort by
recency
|
837 Discussions
|
Please Login in order to post a comment
For Python3 Platform
)
set1 = set(map(int,input().split()))
choice = int(input())
for _ in range(choice): op1, size = input().split() other_set = set(map(int, input().split()))
print(sum(set1))https://)
#What separates my solution is the usage of eval function: which can dynamically execute any text representing a particular function. Most solutions set a conditional logic to determine which function to run.
A_len = int(input()) A_set = set( map(int, input().split(" ")) )
N_len = int(input()) for n in range(N_len): #iteration of 0 to Nth X_str = input().split(" ") X_fx_str = X_str[0] X_set =set( map(int, input().split(" ")) )
eval( f"A_set.{X_fx_str}(X_set)" ) #This is where the eval function used
print(sum(A_set))
for _ in range(N): command = input().split() if command[0] == 'update': A.update(set(map(int, input().split()))) elif command[0] == 'intersection_update': A.intersection_update(set(map(int, input().split()))) elif command[0] == 'difference_update': A.difference_update(set(map(int, input().split()))) elif command[0] == 'symmetric_difference_update': A.symmetric_difference_update(set(map(int, input().split())))
print(sum(A))
N = int(input()) a = set(map(int,input().split()))
b = int(input()) for _ in range(b): operation = input().split() #print(operation) otherset = set(map(int,input().split())) #print(otherset) if len(otherset) == int(operation[1]): if operation[0] == "update": a.update(otherset)
#print(a) elif operation[0] == "intersection_update": a.intersection_update(otherset) #print(a) elif operation[0] == "difference_update": a.difference_update(otherset) #print(a) elif operation[0] == "symmetric_difference_update": a.symmetric_difference_update(otherset) #print(a) else: print("Plese enter according to the Number") print(sum(a))