M
Mark H Harris
Can anyone - maybe one of the Python language core team, or someone
with knowledge of the internals of Python - can explain why this
code works, and whether the different occurrences of the name x in
the expression, are in different scopes or not? :
x = [[1,2], [3,4], [5,6]]
[x for x in x for x in x]
I'll give this +1 for playfulness, and -2 for lack of clarity.
I hope no one thinks this sort of thing is good to do in real-life code.
No. This has to be a better way to flatten lists:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
marcus