On Mon, Nov 24, 2014 at 2:37 AM, Ivan Evstegneev <webmailgro...@gmail.com> wrote: > As I know from books and googling, the comps main idea looks approximately > like this: > > [target <--main loop<--nested loop/s (and maybe some conditions)] Am I > right? > > But your code looks somehow inverted to me o_0 > > Like: > > [[target with nested loop] <--- main loop with initial values for target]
Your analysis is correct, and it's because of the bracketing. Just as you learned back in maths class (or math class, if you're that sort), you start from the innermost brackets and work your way out. In fact, the nested example starts with the main loop, and for each value it goes through, it creates the entire inner comprehension. ChrisA -- https://mail.python.org/mailman/listinfo/python-list