Set Mutations

  • + 10 comments

    I liked this solution better than the editorial:

    (_, A) = (
        raw_input(),
        set(map(int, raw_input().split()))
    )
    
    for _ in xrange(input()):
        (command, newSet) = (
            raw_input().split()[0],
            set(map(int, raw_input().split()))
        )
    
        # Cool trick. Since our commands are method names, just
        # execute the method on A with our new set as its argument.
        getattr(A, command)(newSet)
    
    print str(sum(A))