Remove and Insert
Completed
Start with ["a", "b", "c", "d"]. Read a value to remove and a value to insert at the front. Remove the first value (if present), insert the second at index 0, then print the list.
Input
Two lines.
Output
The final list.
Example
Input
c z
Output
['z', 'a', 'b', 'd']
Editor
Python
Hints
remove(x) deletes the first x but raises an error if x is missing.
insert(index, value) puts a value at a position.
Solution explanation
Checking in first avoids the ValueError from remove.
Show solution
items = ["a", "b", "c", "d"]
old = input()
new = input()
if old in items:
items.remove(old)
items.insert(0, new)
print(items)