x = [1, 2, 3]
y = x
y.append(4)
print("y:", y)
print("x:", x)

###

def destructiveDouble(lst):
    for i in range(len(lst)):
        lst[i] = lst[i] * 2

x = [1, 2, 3]
y = destructiveDouble(x)
print("x:", x)
print("y:", y)

###

def nondestructiveDouble(lst):
    result = []
    for i in range(len(lst)):
        result.append(lst[i] * 2)
    return result

x = [1, 2, 3]
y = nondestructiveDouble(x)
print("x:", x)
print("y:", y)

###

lst = ["a", "a", "c", "d", "e"]
for i in range(len(lst)):
    if lst[i] == "a" or \
       lst[i] == "e":
        lst.pop(i) # index error - range didn't change when lst did

###
        
lst = ["a", "a", "c", "d", "e"]
i = 0
while i < len(lst):
    if lst[i] == "a" or \
       lst[i] == "e":
        lst.pop(i)
    else:
        i = i + 1 # only update index if we didn't remove a value

###

lst = ["a", "a", "c", "d", "e"]
for i in range(len(lst)):
    if lst[i] == "a":
        lst.pop(i)
        break # exits immediately, only removes one "a"