Set .discard(), .remove() & .pop()

  • + 0 comments

    For pypy3

    n = int(input()) s = set(map(int, input().split()))

    n_2 = int(input())

    for i in range(n_2): string = input() try: if "remove" in string or "discard" in string: command, value = string.split() value = int(value) if command == "remove": s.remove(value) elif command == "discard": s.discard(value)

        else:
            r=list(s)
            s=set(r[1:])
    except KeyError:
        pass
    

    print(sum(s))