Hello,

there is something I don't understand about list comprehensions.

I understand how does this work:
print [[y for x in range(8)] for y in range(8)]

However I don't understand why this one works:
print [[y for y in range(8)] for y in range(8)]

In this second example I have one loop nested in another. Both loops uses
the same variable - y. How is it that those loops do not conflict with each
other?

For a moment I thought that maybe list comprehension has its own scope, but
it doesn't seem to be so:
print [[y for y in range(8)] for y in range(8)]
print y

Does anybody understand it?


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to