title: Newbie wanna know how to fix: IndexError: list index out of range
body: <p>So I am working on a project, my code is:</p>
  
  <pre><code>    def show_product():
          choose_a_product = input("OK. Please specify the product's 
      identifier: ")
          product = [p for p in products if p["id"] == choose_a_product][0]
          if product:
              print("SHOWING A PRODUCT HERE!")
              print(dict(product))
          else:
              print("COULDN'T FIND A PRODUCT WITH IDENTIFIER", dict(product))
  </code></pre>
  
  <p>The number of products are around 20. When I input 500000, it can't be run and the mistake is:</p>
  
  <blockquote>
  <pre><code>  File "xx.py", line 35, in show_product
        product = [p for p in products if p["id"] == product_id][0]
    IndexError: list index out of range
  </code></pre>
  </blockquote>
  
  <p>I think the "else" should work, while it doesn't...</p>
  
  <p>Thanks for any help!</p>