Instruction
Good. You could see how our function modified the original list. What if you don't want to do that? What if you want to create a new list without modifying the existing one? Take a look:
def delete_first_element(input_list): copy_list = list(input_list) del copy_list[0] return copy_list
Two things happened:
- We created a new list that is an exact copy of the old list using
copy_list = list(input_list).list()is a built-in function used to copy lists. - We deleted an element from the copy and then returned the copy (
return copy_list). Using this technique, we never actually modify the original list.
Exercise
Run the modified template.
As you can see, the function now returns a new list. The new list is an exact copy of the old list, but has the first element removed. The original list is never modified.



