Python error - IndexError: list index out of range
<p>I am learning python so this might sound simple, I am trying to run the code below but I keep getting the error message shown, any thoughts on what could be causing it?</p>

<pre><code>from geopy import geocoders
import csv

g_api_key = 'my_google_api_key'
g = geocoders.GoogleV3(g_api_key)

costco = csv.reader (open('costcolimited.csv'), delimiter = ',')

# Print header
print "Address, City, State, Zip Code, Latitude, Longitude"
for row in costco:
   full_addy = row[1]+ "," + row[2]+ "," + row[3] + "," + row[4]
   place, (lat,lng) = list (g.geocode(full_addy, exactly_one=FALSE))[0]
   full_addy + "," + str(lat) + "," + str(lng)
</code></pre>

<p>The error I am getting</p>

<pre><code>Traceback (most recent call last):
File "C:\Python27\geocodelocations.py", line 12, in &lt;module&gt;
full_addy = row[1]+ "," + row[2]+ "," + row[3] + "," + row[4]
IndexError: list index out of range
</code></pre>

<p>The error is caused by referring element out of list range. From your code, it is probably because you start counting element from <code>1</code>. Remember that in python list, index starts from <code>0</code>. If this is your situation, then shift indexes in</p>

<pre><code>full_addy = row[1]+ "," + row[2]+ "," + row[3] + "," + row[4]
</code></pre>

<p>to</p>

<pre><code>full_addy = row[0]+ "," + row[1]+ "," + row[2] + "," + row[3]
</code></pre>

<p>Otherwise, check your data structure and make sure it is matched with your code.</p>

<p>Thanks</p>

python python-2.7