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

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.