title: python list comprehension: return a list of strings instead of a list of lists
body: <p>For a homework assignment, we were required to create a function that took in two inputs (list and a string) and that returned a list. I would like to write this function using list comprehension, but have been running into an annoying issue. Here is he original function I would like to re-write:</p>
  
  <pre><code>index = [['keyword1', ['url1', 'url2', 'url3']], ['keyword2', ['url4', 'url5']]...]
  
  def lookup(index, keyword):
      result = []
      for entry in index:
          if entry[0] == keyword:
              result += entry[1]
      return result
  </code></pre>
  
  <p>These were my attempts at using list comprehension:</p>
  
  <pre><code>def lookup(index, keyword):
      return [entry[1] for entry in index if entry[0] == keyword]
  
  def lookup(index, keyword):
      return [ulist for key, ulist in index if i == keyword]
  </code></pre>
  
  <p>and finally...</p>
  
  <pre><code>def lookup(index, keyword):
      return [j for j in (entry[1] for entry in index if entry[0] == keyword)]
  </code></pre>
  
  <p>The problem here is that it returns the desired urls in a list inside of a list, like so:</p>
  
  <pre><code>[['url1', 'url2', 'url3']]
  </code></pre>
  
  <p>instead of the desired format of:</p>
  
  <pre><code>['url1', 'url2', 'url3']
  </code></pre>
  
  <p>I thought of just doing something like this (adding [0] to the end of the return statement so it gives me the inner list):</p>
  
  <pre><code>def lookup(index, keyword):
          return [j for j in (entry[1] for entry in index if entry[0] == keyword)][0]
  </code></pre>
  
  <p>But it just doesn't seem like the right way. Am I trying to use list comprehension unnecessarily (my understanding was that this situation was well suited for list comprehension)? Any suggestions?</p>