$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · hard · #215

What is the output?

a = [1, 2, 3]
for x in a:
    a.remove(x)
print(a)
  1. []
  2. [3]
  3. [1, 3]
  4. [2]
Removing 1 shifts 2 into index 0, so the loop skips it, removes 3, and stops.
Play Problem Solving ▸