+ 1
Create a function that duplicates every integer in a list
I have to write a function that accepts a list of integers as a parameter and replaces every element with two copies of itself. For example, if a list named nums stores [1, 2, 3], the call of stutter(nums) should change it to store [1, 1, 2, 2, 3, 3]. This is what I tried, but it does't work. def stutter(list): a = list b = [] for i in a: b.extend([i, i]) stutter([1, 2, 3])
1 Answer
0
How do i modify this so that rather than creating and printing a new list (b), I simply change the values in the original lists that is passes in as a parameter? I'm just trying to modify the original list (a) but the error it's giving me is unsupported 'int' type error because it's reading my integer list as a string.