close

[Solved] TypeError: argument of type ‘int’ is not iterable

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error TypeError: argument of type ‘int’ is not iterable in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How TypeError: argument of type ‘int’ is not iterable Error Occurs?

Today I get the following error TypeError: argument of type ‘int’ is not iterable in python.

How To Solve TypeError: argument of type ‘int’ is not iterable Error ?

  1. How To Solve TypeError: argument of type 'int' is not iterable Error ?

    To Solve TypeError: argument of type 'int' is not iterable Error Based on the OP's comment It should print "t" if there is a 0 in a row and there is not a 1 in the row.

  2. TypeError: argument of type 'int' is not iterable

    To Solve TypeError: argument of type 'int' is not iterable Error Based on the OP's comment It should print "t" if there is a 0 in a row and there is not a 1 in the row.

Solution 1

Here c is the index not the list that you are searching. Since you cannot iterate through an integer, you are getting that error.

>>> myList = ['a','b','c','d']
>>> for c,element in enumerate(myList):
...     print c,element
... 
0 a
1 b
2 c
3 d

You are attempting to check if 1 is in c, which does not make sense.

Solution 2

Based on the OP’s comment It should print "t" if there is a 0 in a row and there is not a 1 in the row.

change if 1 not in c to if 1 not in row

for c, row in enumerate(matrix):
    if 0 in row:
        print("Found 0 on row,", c, "index", row.index(0))
        if 1 not in row: #change here
            print ("t")

Further clarification: The row variable holds a single row itself, ie [0, 5, 0, 0, 0, 3, 0, 0, 0]. The c variable holds the index of which row it is. ie, if row holds the 3rd row in the matrix, c = 2. Remember that c is zero-based, ie the first row is at index 0, second row at index 1 etc.

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read