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.
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)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Set .discard(), .remove() & .pop()
You are viewing a single comment's thread. Return to all comments →
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)