954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

int() syntax interacting with list calls

Hi,

I am having some trouble using the int function on an element of a list. My code currently looks like this.

for j in range(int(L)):
         for k in range(int(Allele[j])):
              alleleslocus_j.insert(k,loci.readline())

where Allele is a list of length L inputted by the user. I am having problems with the second line. When I run the program I get the error ValueError: invalid literal for int() with base 10: '['. I think that something about calling from the list is interacting with the int() syntax. I am wondering what exactly the problem is and how would I deal with it. Thanks!

Elise

PS This is a python program but I am compiling it in Sage

echellwig
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

The error is being raised because it is trying to find the integer value of the character '[', which is apparently part of your list. You could either put in a try/except statement to 'pass' when you run into those, or print out the contents of the list and manually remove bogus entries.

Just post back if you need help with any of that.

SoulMazer
Posting Whiz in Training
213 posts since Sep 2008
Reputation Points: 23
Solved Threads: 12
 

Thanks so much for your help! I figured out my problem (I accidentally added brackets at the beginning and end of my list). it's fixed now.

Elise

echellwig
Newbie Poster
21 posts since Jun 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: