Python | Set .discard(), .remove() & .pop() | Hackerrank Solution
HTML-код
- Опубликовано: 11 сен 2024
- #python
#hackerrank
#hackerranksolution
#set.discard()
#set.remove()
#set.pop()
#set.discard()hackerrank
#set.remove()hackerrank
#set.pop()hackerrank
Python Hackerrank Challenge Tutorial
Sets - Set .discard(), .remove() & .pop()
you don't need the second for loop in new version of python.
you simply can use sum(set()) to get the total
Code ain't working
n = int(input())
s = set(map(int,input().split()))
no_of_commands = int(input())
for item in range(no_of_commands):
cmd = input().split()
if cmd[0] == "pop":
s.pop()
if cmd[0] == "remove":
s.remove(int(cmd[1]))
if cmd[0] == "discard":
s.discard(int(cmd[1]))
total = 0
for item in s:
total = total + item
print(total)
program is not working, check once
change language from "Pypy3" to "Python3"