You are viewing a single comment's thread. Return to all comments →
With getattr, assuming you have loaded the input into a set named s
for _ in range(N): method, *args = input().split() getattr(s, method)(*map(int,args))
Of course, that will allow any method. If you want a) only to allow the specified methods and b) slightly faster lookups
methods = { 'pop' : s.pop, 'remove' : s.remove, 'discard' : s.discard } for _ in range(N): method, *args = input().split() methods[method](*map(int,args))
Seems like cookies are disabled on this browser, please enable them to open this website
Set .discard(), .remove() & .pop()
You are viewing a single comment's thread. Return to all comments →
With getattr, assuming you have loaded the input into a set named s
Of course, that will allow any method. If you want a) only to allow the specified methods and b) slightly faster lookups