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.
Set .discard(), .remove() & .pop()
Set .discard(), .remove() & .pop()
Sort by
recency
|
1056 Discussions
|
Please Login in order to post a comment
WHY NOT WORKING? n = int(input()) st = [] for i in range(n): st.extend(map(int, input().split()))
o = int(input()) for _ in range(o): oper = input().split() if oper[0] == 'pop': if st:
st.pop() elif oper[0] == 'remove': y = int(oper[1]) if y in st: st.remove(y) elif oper[0] == 'discard': y = int(oper[1]) if y in st: st.remove(y)
print(st)
If anyone is hitting a snag using PyPy, switch to Python3. There is some deterministic way that pop removes items from the set that breaks subsequent calls to remove().
If anyone is hitting a snag using PyPy, switch to Python3. There is some deterministic way that pop removes items from the set that breaks subsequent calls to remove().
Thanks