0

I really don't understand this for loop:

 output = ', '.join([q.question_text for q in latest_question_list])

I understand what for q in latest_question_list is doing. But im used to then having a code block underneath, not in front of the loop.

I don't understand how exactly this works or what it is even called to search it lol.

jarjarbinks99
  • 165
  • 1
  • 7
  • 1
    list comprehension – Daniel Jun 21 '22 at 14:58
  • ok ill google that – jarjarbinks99 Jun 21 '22 at 14:58
  • it is first creating a list of text and then joining those text with `, ` – sahasrara62 Jun 21 '22 at 15:01
  • for every question (called `q`) in `latest_question_list` (seems to be a list of questions), get the text (`q.question_text` ) and put it in a list (that's what the `[q.question_text......]` mean). Then you have a list of questions texts, and join them with `', `. suppose that you have latest_question_list with 2 questions with text `lates_question_list[0].question_text = 'why?` and `lates_question_list[0].question_text = 'where?` Then you get the both question texts as `['why?','where?']` (this is maked by the comprehension). Then join them: `'why?, where?` – Ulises Bussi Jun 21 '22 at 15:03

0 Answers0