Python | Set .discard(), .remove() & .pop() | Hackerrank Solution

preview_player
Показать описание
#python
#hackerrank
#hackerranksolution

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

rahulagre
Автор

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

preetamsingh
join shbcf.ru