0

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

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by echellwig
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.

Edited by SoulMazer: n/a

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.