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
|
818 Discussions
|
Please Login in order to post a comment
Can we make it even more concise?
Enter your code here. Read input from STDIN. Print output to STDOUT
n = input() A = set(map(int, input().split())) num_other_sets = input() for _ in range(int(num_other_sets)): eachset = [input().split()[0], set(map(int, input().split()))] if eachset[0] == "update": A.update(eachset[1]) elif eachset[0] == "intersection_update": A.intersection_update(eachset[1]) elif eachset[0] == "symmetric_difference_update": A.symmetric_difference_update(eachset[1]) elif eachset[0] == "difference_update": A.difference_update(eachset[1])
print(sum(A))
set_a_count = int(input()) set_a = set(map(int,input().split())) n = int(input()) for i in range (n): operation = input().split() set_b = set(map(int,input().split())) if operation[0] == "update": set_a.update(set_b) elif operation[0] == "intersection_update": set_a.intersection_update(set_b) elif operation[0] == "difference_update": set_a.difference_update(set_b) else: set_a.symmetric_difference_update(set_b)
print(sum(set_a))
m = int(input()) A = input() n = int(input())
setA = set(map(int, A.split()))
for i in range(n): line1 = input() B = input()
sum = 0 for i in setA: sum = sum + i print(sum)