Challenge - #63 - Set Mutations

 def updateit(setA,s,command):

    if command == "update":
        setA.update(s)
    elif command == "difference_update":
        setA.difference_update(s)
    elif command == "intersection_update":
        setA.intersection_update(s)
    else :
        setA.symmetric_difference_update(s)
    return setA


a = int(input())
setA =set(map(int,input().split()))

for i in range(int(input())):
    command, len_of_set = input().split()
    s = set(map(int,input().split()))
    setA = updateit(setA,s,command)
print(sum(setA))

Comments

Popular posts from this blog

Challenge - #48 - Incorrect Regex

Challenge - #43 - Time Delta

Challenge - #52 - Set .discard(), .remove(), & .pop()