Three Ways to Copy
Python
25 pts
Three Ways to Copy
Make three real copies of cities, each in a different way:
copy1withcopy()copy2withlist()copy3with a full slice[:]
Then change each copy: add "Assab" to the end of copy1, replace the first item of copy2 with "Nakfa", and remove "Keren" from copy3. The original must not change.
Print cities, copy1, copy2, copy3. Expected output:
['Asmara', 'Keren', 'Massawa'] ['Asmara', 'Keren', 'Massawa', 'Assab'] ['Nakfa', 'Keren', 'Massawa'] ['Asmara', 'Massawa']
Checklist
- Create
copy1,copy2andcopy3as real copies, usingcopy(),list()and[:]. - Add
"Assab"to the end ofcopy1. - Replace the first item of
copy2with"Nakfa". - Remove
"Keren"fromcopy3, and keepcitiesunchanged. - Print
cities,copy1,copy2andcopy3.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
