Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
List basics
Lists with if statements and loops
Lists in functions
19. Returning lists from functions


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:

  1. 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.
  2. 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.


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.