0

I'm following the official tutorial on Django and i came across this lines

def index(request):
   latest_question_list = Question.objects.order_by('-pub_date')[:5]
   output = ', '.join([q.question_text for q in latest_question_list])
   return HttpResponse(output)

It's everything clear except for the for in loop and i can't find anywhere where to understand how it is written.

Why q.question_text is BEFORE the for in loop?

I already looked at the other question questioning this line of code, but i cannot fine anywhere some python documentation that explain me how the syntax of this loop works, even though i can understand what it does.

Also i'm new to python and i am clearly miss something...

vitta
  • 101
  • 2
  • 2
  • 11
  • Enjoy the [read](http://www.pythonforbeginners.com/basics/list-comprehensions-in-python) :) – zipa Jun 26 '18 at 10:23
  • 1
    It's not a for loop, it's a [list comprehension](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions). – Tyson Jun 26 '18 at 10:24
  • thanks.... i wans't even able to understand what i was looking for... – vitta Jun 26 '18 at 10:28

0 Answers0