Advertisement
pacho_the_python

Untitled

Feb 23rd, 2022
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. numbers = input().split(' ')
  2. numbers = list(map(int, numbers))
  3.  
  4.  
  5. command = input().split(" ")
  6.  
  7. while True:
  8.     if command[0] == "Finish":
  9.         break
  10.  
  11.     if command[0] == "Add":
  12.         numbers.append(command[1])
  13.  
  14.     elif command[0] == "Remove":
  15.         numbers.remove(int(command[1]))
  16.  
  17.     elif command[0] == "Replace":
  18.         value = int(command[1])
  19.         replacement = int(command[2])
  20.         counter = 0
  21.         for i in range(len(numbers)):
  22.  
  23.             if numbers[i] == value:
  24.                 numbers.remove(value)
  25.                 numbers.insert(i, replacement)
  26.                 counter += 1
  27.  
  28.             if counter >= 1:
  29.                 break
  30.  
  31.     elif command[0] == "Collapse":
  32.         collapse = int(command[1])
  33.  
  34.         numbers = [x for x in numbers if x > collapse]
  35.  
  36.     command = input().split(" ")
  37.  
  38. numbers = list(map(str, numbers))
  39. output = " ".join(numbers)
  40. print(output)
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement