Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8438417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:42:34+00:00 2026-06-10T07:42:34+00:00

i am doing this: def GetDistinctValues(theFile, theColumn): lines=theFile.split(‘\n’) allValues=[] for line in lines: allValues.append(line[theColumn-1])

  • 0

i am doing this:

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

i am getting string index out of range on this line:

allValues.append(line[theColumn-1])

does anyone know what i am doing wrong?

here’s the complete code if needed:

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) < 3:
          break
        elif len(y) > 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;')

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

        r += '\n<Placemark><name>'+y[2].encode('utf-8','xmlcharrefreplace')+'</name>' \
          '\n<description>'+desc.encode('utf-8','xmlcharrefreplace')+'</description>\n' \
          '<Point><coordinates>'+y[0]+','+y[1]+'</coordinates></Point>\n</Placemark>'
    r += readFile('footer.txt')
    f = open(theHash,'w')
    f.write(r)
    f.close()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T07:42:36+00:00Added an answer on June 10, 2026 at 7:42 am

    The error isn’t caused by append(), It’s because the line isn’t long enough. Maybe your file has a empty line at the end. You could try

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

    otherwise an exception handler can help find what’s going wrong

    def GetDistinctValues(theFile, theColumn):
      lines=theFile.split('\n')
      allValues=[]
      for line in lines:
         try:
            allValues.append(line[theColumn-1])
         except IndexError:
            print "line: %r"%line
      return list(set(allValues))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I'm doing it in this fashion: class Spam(object): decorated = None @classmethod def
I am doing this to replace whitespaces and line breaks. The whitespaces part works
The current way I'm doing this is like this: def avatar_geometry width = 0
I am doing this (in Groovy): def cookies=webClient.cookieManager.cookies def http=new HTTPBuilder(myurl) http.request(POST) { def
In python I can do this: def f((a, b)): return a + b d
I m doing this def power_two(n, base = -1): result = 2 ** base
I have something like this using BeautifulSoup: for line in lines: code = l.find('span',
Im doing this project where i need to download files through a webservice (images,
I am interested in doing this C code in Java: // sets n's ith
I am doing this currently, class Page { // variable to hold DBC class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.