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

  • + 2 comments

    The issue is with "pop", it should pop the samllest element from the set but instead it is removing the last element from the set. I just want to understand why it is happening? here is my code

    n = int(input())
    lst = set(map(int, input().split()))
    num = int(input())
    for i in range(num):
        st = input().strip()
        if ' ' in st:
            x, y = st.split()
            y = int(y)
            if y in lst:
                getattr(lst, x)(y)
        else:
            if lst:
                getattr(lst, st)()
    print(sum(lst))