appending values to a list in python
<p>i am doing this:</p>

<pre><code>def GetDistinctValues(theFile, theColumn):
  lines=theFile.split('\n')
  allValues=[]
  for line in lines:
    allValues.append(line[theColumn-1])
  return list(set(allValues))
</code></pre>

<p>i am getting  <code>string index out of range</code> on this line:</p>

<pre><code>allValues.append(line[theColumn-1])
</code></pre>

<p>does anyone know what i am doing wrong?</p>

<p>here's the complete code if needed:</p>

<pre><code>import hashlib

def doStuff():
  createFiles('together.csv')

def readFile(fileName):
  a=open(fileName)
  fileContents=a.read()
  a.close()
  return fileContents

def GetDistinctValues(theFile, theColumn):
  lines=theFile.split('\n')
  allValues=[]
  for line in lines:
    allValues.append(line[theColumn-1])
  return list(set(allValues))

def createFiles(inputFile):
  inputFileText=readFile(inputFile)
  b = inputFileText.split('\n')
  r = readFile('header.txt')
  DISTINCTCOLUMN=12
  dValues = GetDistinctValues(inputFileText,DISTINCTCOLUMN)

  for uniqueValue in dValues:
    theHash=hashlib.sha224(uniqueValue).hexdigest()
    for x in b:
      if x[DISTINCTCOLUMN]==uniqueValue:
        x = x.replace(', ',',').decode('latin-1','ignore')
        y = x.split(',')
        if len(y) &lt; 3:
          break
        elif len(y) &gt; 3:
          desc = ' '.join(y[3:])
        else:
          desc = 'No description'
        # Replacing non-XML-allowed characters here (add more if needed)
        y[2] = y[2].replace('&amp;','&amp;amp;')

        desc = desc.replace('&amp;','&amp;amp;')

        r += '\n&lt;Placemark&gt;&lt;name&gt;'+y[2].encode('utf-8','xmlcharrefreplace')+'&lt;/name&gt;' \
          '\n&lt;description&gt;'+desc.encode('utf-8','xmlcharrefreplace')+'&lt;/description&gt;\n' \
          '&lt;Point&gt;&lt;coordinates&gt;'+y[0]+','+y[1]+'&lt;/coordinates&gt;&lt;/Point&gt;\n&lt;/Placemark&gt;'
    r += readFile('footer.txt')
    f = open(theHash,'w')
    f.write(r)
    f.close()
</code></pre>
