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.
Since the commands are the exact name of the method calls on the Set you can use python's getattr function as shown below. NOTE - do not do this in production code unless you are guaranteed that the method calls are correct!!
input()#throwawayA=set(map(int,input().split()))N=int(input())for_inrange(N):cmd=input().split()#throwawaycmd[1]s=set(map(int,input().split()))# get the cmd[0] method from A and call with param sgetattr(A,cmd[0])(s)print(sum(A))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Set Mutations
You are viewing a single comment's thread. Return to all comments →
Since the commands are the exact name of the method calls on the Set you can use python's getattr function as shown below. NOTE - do not do this in production code unless you are guaranteed that the method calls are correct!!