title: Django - render relevant value from queryset in template
body: <p>I am rendering data from my views into my template, as follows:</p>
  <pre><code>&lt;tbody&gt;
      {% for item in lyrics %}
      &lt;tr class='lyrics-table'&gt;
        &lt;td&gt;{{item}}&lt;/td&gt;
        &lt;td&gt;
        {% if item in user_flash %}
           &lt;p&gt;{{flash_answer}}&lt;/p&gt;
         {% else %}
          &lt;p&gt;xxx&lt;/p&gt;
        {% endif %}
       &lt;/td&gt;
  </code></pre>
  <p>My views are as follows:</p>
  <pre><code>class SongVocab(LoginRequiredMixin, generic.DetailView):
      model= models.Song
      template_name = 'videos/song_vocab.html'
      context_object_name = 'song'
  
      def get_context_data(self, **kwargs):
          context = super().get_context_data(**kwargs)
  
          from pymystem3 import Mystem
          m = Mystem()
          user_flash = Flashcard.objects.filter(owner=self.request.user).values_list('question', flat=True)
          lyrics_list = models.Song.objects.get().lyrics_as_list()
          user_flash_ = [item.replace('\n', ' ') for item in m.lemmatize(&quot; &quot;.join(user_flash))]
          user_flash_clean = [w for w in user_flash_ if w.strip()]  ##removes empty strings
          lyrics_list_ = [item.replace('\n', ' ') for item in m.lemmatize(&quot; &quot;.join(lyrics_list))]
          lyrics_list_clean = [w for w in lyrics_list_ if len(w.strip())]
          user_word = list(set(user_flash_clean) &amp; set(lyrics_list_clean))
  
          import icu # PyICU
          def sorted_strings(strings, locale=None):
              if locale is None:
                  return sorted(strings)
              collator = icu.Collator.createInstance(icu.Locale(locale))
              return sorted(strings, key=collator.getSortKey)
          context['percent_known'] = ((len(user_word))/(len(set(lyrics_list_clean))))*100
          context['lyrics'] = sorted_strings(set(lyrics_list_clean),&quot;ru_RU.UTF8&quot;)
          context['user_flash'] = user_flash_clean
  
          context['flash_answer'] = []
          for word in user_word:
          flash = Flashcard.objects.get(owner=self.request.user, question=word)
          context['flash_answer'].append(flash.answer)
  
      return context
  </code></pre>
  <p>My question is: how can I render the relevant <code>flash_answer</code> for every <code>user_word</code> in my template? At the moment, I get the entire queryset, which makes sense, because that is what <code>flash_anwswer</code> is. But the two are linked, so there must be a way, but I have no idea how to do it. Do I need to change my view, or is there a way I can render it differently in the template?</p>
  <p><strong>Update</strong> - I'm now thinking that I need to create a dictionary in my views, but I'm not sure how to do it. So I have:</p>
  <p><code>user_word</code> - gives a list containing words where the user's flashcard overlaps with a word in lyrics.</p>
  <p>So how can I now get a dictionary that shows for example:</p>
  <p><code>{'question': relevant word from lyrics, 'answer': flash_answer}</code></p>
  <p>But how can I match the two and get &quot;relevant word from lyrics&quot;? Almost like doing a vlookup in excel... I'm completely lost!</p>
  <p><strong>Update</strong>: I tried this, which sort of works, except I get only one value instead of all of them...</p>
  <pre><code>    z = []
      m = {'question': [], 'answer': []}
      for word in user_word:
          x = lyrics_list_clean.index(word)
          y = user_word.index(word)
          flash = Flashcard.objects.get(owner=self.request.user, question=word)
          z.append(flash.answer)
          m['question'].append(lyrics_list_clean[x])
          m['answer'].append(z[y])
          context['test'] = m
  </code></pre>