From 1294c4eda33aa14ecd36e138427c61769c6df6b9 Mon Sep 17 00:00:00 2001 From: gajanan badge <72186802+gajubadge11@users.noreply.github.com> Date: Fri, 2 Oct 2020 01:30:16 +0530 Subject: [PATCH] Create set mutation hackerrank solution --- python/set mutation | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 python/set mutation diff --git a/python/set mutation b/python/set mutation new file mode 100644 index 0000000..6888838 --- /dev/null +++ b/python/set mutation @@ -0,0 +1,21 @@ +if __name__ == "__main__": + n = int(input()) + s = set(map(int, input().split())) + num_cmds = int(input()) + + for _i in range(num_cmds): + cmd = list(input().strip().split(' ')) + if cmd[0] == 'intersection_update': + get_set = set(map(int, input().split(' '))) + s &= get_set + elif cmd[0] == 'update': + get_set = set(map(int, input().split(' '))) + s |= get_set + elif cmd[0] == 'difference_update': + get_set = set(map(int, input().split(' '))) + s -= get_set + elif cmd[0] == 'symmetric_difference_update': + get_set = set(map(int, input().split(' '))) + s ^= get_set + + print(sum(s))