Niles Bernoulli
Niles Bernoulli

Reputation: 127

Iterating through lists

I have a list that looks like this:

A = [(1,1,1,2,2), (1,1,3,2,2), (1,1,6,2,2), (1,1,5,2,2), (1,1,2,5,2), (2,1,1,1,2) ...]

I'm running the elements through a simple for-loop like so:

n = len(A);
for p in [0..n-1] :
     a1 = A[p][5*p]
     a2 = A[(p+1)][5*(p+1)]
     .
     .

and I'm getting: 'int' object is not iterable. I've no idea why this isn't working.

quick edit:

Ideal output: every a1 is like--a1 = A[0][0], then a1 = A[1][5], then a1 = A[2][10] and on.

Upvotes: 0

Views: 95

Answers (2)

Steve Barnes
Steve Barnes

Reputation: 28405

Given what you are trying to do:

for p in A:
    print p[0],p[4]

Upvotes: 1

Thorsten Kranz
Thorsten Kranz

Reputation: 12765

Seems like you're used to matlab. Try:

for p in range(n):

Anyway, you'll get index problems with using `A[p][5*p].

Upvotes: 0

Related Questions