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()

Комментарии • 4

  • @rahulagre9750
    @rahulagre9750 Месяц назад

    you don't need the second for loop in new version of python.
    you simply can use sum(set()) to get the total

  • @krutarthpatel2823
    @krutarthpatel2823 Год назад

    Code ain't working

  • @preetamsingh722
    @preetamsingh722 Год назад

    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