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
|
849 Discussions
|
Please Login in order to post a comment
number_element = int(input()) number_element_spaced = set(map(int, input().split())) numbers_of_other_sets = int(input())
for _ in range(numbers_of_other_sets): operations , no_elements = input().split() other_sets = set(map(int, input().split())) getattr(number_element_spaced,operations)(other_sets)
print(sum(number_element_spaced))
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() room = list(map(int,input().split())) uroom = set(room) for x in uroom: room.remove(x) print(uroom.difference(set(room)).pop())