title: Python : Cannot access list element even though it exists
body: <p>I'm trying to write a code to extract data from a website using <strong>Python</strong> and its <em>urllib2</em> and <em>BeautifulSoup</em> libraries.</p>
  
  <p>I tried iterating over the rows of the desired table and then storing the data in each row specified in "td" into a list variable row_data. Event though I can get the entire list to print, I cannot access the list at specific indexes and the interpreter throws up "list index out of range" error. Here goes my code and the output.</p>
  
  <pre><code>import urllib2
  from bs4 import BeautifulSoup
  
  link = 'http://www.babycenter.in/a25008319/most-popular-indian-baby-names-of-2013'
  page = urllib2.urlopen(link)
  soup = BeautifulSoup(page)
  right_table = soup.find('table', class_= 'contentTable colborders')
  name=[]
  meaning=[]
  alternate=[]
  
  for row in right_table.find_all("tr"):
    row_datas = row.find_all("td")
    print row_datas
    print row_datas[0]
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>[]Traceback (most recent call last):
    File "C:\Users\forcehandler\Documents\python\data_scrape.py", line 41, in &lt;module&gt;
  
  print row_datas[0]
  IndexError: list index out of range
  [Finished in 1.6s]
  </code></pre>
  
  <p>I tried similar code to mark out any obvious errors but to no avail.
  Code:</p>
  
  <pre><code>i = [range(y,10) for y in range(5)]
  for j in i:
    print j
    print j[0]
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  0
  [1, 2, 3, 4, 5, 6, 7, 8, 9]
  1
  [2, 3, 4, 5, 6, 7, 8, 9]
  2
  [3, 4, 5, 6, 7, 8, 9]
  3
  [4, 5, 6, 7, 8, 9]
  4
  </code></pre>
  
  <p>I'm new to programming and couldn't find help anywhere else. Thanks in advance!</p>
  
  <p>Edit: The '[]' before Traceback might have accidentally slipped into the output while copy-pasting. And thanks for the you helpful answers/suggestions.</p>
  
  <p>Solution: I didn't check the integrity of data before putting it to use. As it turns out, the first row consisted of only 'th' values and no 'td' values and hence the error.</p>
  
  <p>Lesson: Always test the data before putting it to any use.</p>
  
  <p>On a side note: This is my first question on StackOverflow and I am overwhelmed with such quick, quality and helpful responses.</p>