0

I am new to Python, I am trying to solve following problem.

Given a list, find even numbers and replace it with 2 of the same.

Sample input:

[2,5,4,0]

Sample output:

[2,2,5,4,4,0,0]

My solution:

l2 = [2,5,4,0]
def dupEven(l2):
    l3 = l2
    for i in l2:
        if i % 2 == 0:
            l3.insert(l3[i],i)

If I try to run the program, it is going in loop as it seems the old list (l1) keeps getting updated whenever the new list getting updated (l2).

How can I stop the old list getting updated when I update the new list in Python?

smc
  • 2,175
  • 3
  • 17
  • 30

0 Answers0