Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The expression is a list comprehension with 2 nested for statements. It is similar to this, which names its result:

   result = []
   for l in a:
      for x in l:
         result.append(x)


Yes. And the order of the two for's in the list comprehension was deliberately kept the same as the order of the two for loops in your explicit code, on purpose, for ease of remembering how the former (i.e. list comp) works.


That order is the part that confused me. I expected to read it right-to-left, instead it's left to right for the for statements, then the expression on the left at the end.

I see now that the Python docs explain this very clearly...


Yes. Meant to say that but forgot - that the Python docs explain it. That's where I read it myself :)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: