Shopping List Python
Здравейте,
някой би ли погледнал решението ми? Разбирам какъв е проблемът, но не знам как да го поправя. Знам, че има много по-просто решение, но исках да упражня функциите:
Input
You will receive an initial list with groceries separated by "!".
After that you will be receiving 4 types of commands, until you receive "Go Shopping!"
- Urgent {item} - add the item at the start of the list. If the item already exists, skip this command.
- Unnecessary {item} - remove the item with the given name, only if it exists in the list. Otherwise skip this command.
- Correct {oldItem} {newItem} – if the item with the given old name exists, change its name with the new one. If it doesn't exist, skip this command.
- Rearrange {item} - if the grocery exists in the list, remove it from its current position and add it at the end of the list.
Constraints
- There won`t be any duplicate items in the initial list
Output
Print the list with all the groceries, joined by ", ".
- "{firstGrocery}, {secondGrocery}, …{nthGrocery}"
Examples
Input |
Output |
Tomatoes!Potatoes!Bread Unnecessary Milk Urgent Tomatoes Go Shopping! |
Tomatoes, Potatoes, Bread |
Input |
Output |
Milk!Pepper!Salt!Water!Banana Urgent Salt Unnecessary Grapes Correct Pepper,Onion Rearrange Grapes Correct Tomatoes,Potatoes Go Shopping! |
Milk, Onion, Salt, Water, Banana |
Много благодаря, не знаех какво прави .split(' ',1)!
Сега остава само да оправя останалите проблеми :)