Predict

The Lamp Trap

Closures remember variables, not the values they held at the time. Watch the loop.

def make_lamps():
    lamps = []
    for i in range(3):
        lamps.append(lambda: i)
    return lamps

print([lamp() for lamp in make_lamps()])

What does this program print?