In this HackerRank Set .discard(), .remove() & .pop() problem solution You have a non-empty set s, and you have to execute N commands given in N lines. The commands will be pop, remove and discard.
HackerRank Set .discard(), .remove() & .pop() in python problem solution
n = input()
s = set(map(int, raw_input().split()))
length = int(raw_input())
for i in range(0, length):
kwargs = raw_input().strip().split(" ")
if kwargs[0] == "pop":
s.pop()
elif kwargs[0] == "remove":
s.remove(int(kwargs[1]))
elif kwargs[0] == "discard":
s.discard(int(kwargs[1]))
print sum(s)
0 Comments