8.3 Mistake #3: Trying to Iterate Through Something that Cannot be Iterated
I see people doing something like this very often:
sequenceLength = len("ATCGCTGACTAGCTAGTCGTGATTCTACGCTAGCTAGCTAT")
for i in sequenceLength:
# Do stuff here...However, this will not work. sequenceLength is an integer - you cannot iterate through integers!
8.3.1 What can I do to avoid this?
For one, do definitely have a good grasp on what you can and cannot iterate through. You cannot iterate through numeric values; however, you can iterate through lists, strings, and dictionaries!
Furthermore, if you are having a hard time remembering what a variable is, then you may want to consider one of or both of the following:
- Name your variables something intuitive.
sequenceLengthis intuitive enough to the point that you can guess that it’s going to be a numeric value of some sort. - Leave comments on your variable(s). This way, you won’t trip yourself over.