Advertisement
GalinaKG

Shopping List

Jun 21st, 2022
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. list_with_groceries = input().split('!')
  2. command = input()
  3.  
  4. while command != 'Go Shopping!':
  5.     command = command.split()
  6.  
  7.     if 'Urgent' in command:
  8.         item = command[1]
  9.         if item not in list_with_groceries:
  10.             list_with_groceries.insert(0, item)
  11.  
  12.     elif 'Unnecessary' in command:
  13.         item = command[1]
  14.         if item in list_with_groceries:
  15.             list_with_groceries.remove(item)
  16.  
  17.     elif 'Correct' in command:
  18.         old_item = command[1]
  19.         new_item = command[2]
  20.         if old_item in list_with_groceries:
  21.             for index, item in enumerate(list_with_groceries):
  22.                 if item == old_item:
  23.                     list_with_groceries[index] = new_item
  24.  
  25.     elif 'Rearrange' in command:
  26.         item = command[1]
  27.         if item in list_with_groceries:
  28.             list_with_groceries.remove(item)
  29.             list_with_groceries.append(item)
  30.  
  31.     command = input()
  32.  
  33. print(', '.join(list_with_groceries))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement