0

I keep getting the error 'int' object is not iterable, but I can't figure out why, any suggestions?

def printMatching(seq1, seq2):
is_match = []
if len(seq1) < len(seq2):
    short_seq = seq1
else:
    short_seq = seq2
for i in len(short_seq):
    if seq1(i) == seq2(i):
        is_match.append(true)
    else:
        is_match.append(false)

def main():
    seq1 = "abaababb"
    seq2 = "aabbaababa"
    printMatching(seq1, seq2)
1
  • for i in len(short_seq) is wrong. One can't iterate a number. It is just a number. Use for i in range(num) to iterate [0..n) or just iterate the sequence directly. In this case I suspect that using zip and/or comprehensions would be useful. Commented Sep 11, 2014 at 3:37

2 Answers 2

3
for i in range(len(short_seq))

You're currently looping over a single number, which is not allowed. range(int) creates a list of values from [0,input).

Sign up to request clarification or add additional context in comments.

Comments

0
for i in len(short_seq): 

This line has errors. You need to have something like

for i in range(len(short_seq)):

i in - This basically checks for i in a iterable. Since len(short_seq) is not a iterable, it throws an error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.