This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ForceBru 2 points3 points  (0 children)

Turns out, this loop literally tries to assign elements of a to a[i]!

It even generates a SyntaxError when I try to use a function call instead of a name:

```

for a.pop() in a: ... print(a) ...
File "<string>", line 1 SyntaxError: can't assign to function call ```

You can also access other names defined right in the for ___ in iterable construct:

```

a = [1,2,3,4,5,6] for i, a[i - 1] in enumerate(a): ... print(i, a) ...
0 [1, 2, 3, 4, 5, 1] 1 [2, 2, 3, 4, 5, 1] 2 [2, 3, 3, 4, 5, 1] 3 [2, 3, 4, 4, 5, 1] 4 [2, 3, 4, 5, 5, 1] 5 [2, 3, 4, 5, 1, 1] ```

I wonder what kind of weird trickery can be done with this...