Cloning a List

Tags: Lists, Slicing

Write a Python function to clone or copy a list. The function should return a new list that contains all elements from the original list.

Example 1:

Input: [1,2,3,4,5] 
Output: [1,2,3,4,5]

Example 2:

Input: ['a', 'b', 'c', 'd', 'e'] 
Output: ['a', 'b', 'c', 'd', 'e']

You can use slicing to clone the list.

def clone_list(original_list):
    return original_list[:]

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!