Comprehension with two variables - explanation needed
Chris Angelico
rosuav at gmail.com
Sun Nov 23 10:42:16 EST 2014
More information about the Python-list mailing list
Sun Nov 23 10:42:16 EST 2014
- Previous message (by thread): Comprehension with two variables - explanation needed
- Next message (by thread): Comprehension with two variables - explanation needed
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Nov 24, 2014 at 2:37 AM, Ivan Evstegneev <webmailgroups at 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
- Previous message (by thread): Comprehension with two variables - explanation needed
- Next message (by thread): Comprehension with two variables - explanation needed
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list