Lesson 05-06: Building List Functions: extend

Learning Target: I can create a python function that will combine two lists.

Assignment

In the area below, create a function called extend() that will take in two arguments, a list called original and a list called extension. The function should alter original by adding the elements of extension onto original, keeping the same order.

You may only use the following list methods: append(), insert(), remove(), len().

Example:

list1 = [1,2,3]
list2 = [7,8,9]
extend(list1,list2)
print(list1)

This should print the following: [1,2,3,7,8,9].

Hints

Remember that you can modify lists within functions and it will stay modified when you’re done with the function!
You’ll have to add elements from extension to original, one by one, using the append() list function.

Here’s one way to do it:

def extend(original,extension):
    for element in extension:
        original.append(element)
Next Section - Lesson 05-08: Building List Functions: replaceAll