I saw an example about using nested loop in pyhton.
students = [['Igor', 'Sokolov'], ['Riko', 'Miyazaki'], ['Tuva', 'Johansen']]
for student in students:
for name in student:
print(name)
print()
I want to use same thing below:
def id_validator(verified_ids,feedback_ids):
for ids in id_validator:
for x in ids:
print(x)
id_validator([5, 8], [5,8,30,50])
I expected to see
5
8
5
8
30
50
but I got a Type Error:’function’ object is not iterable
>Solution :
Your problem is that you are using the same name id_validator for both the function and the loop variable! to fix this, you need to use a different variable name for the loop!
so check this out:
def id_validator(verified_ids, feedback_ids):
for ids in [verified_ids, feedback_ids]:
for x in ids:
print(x)
id_validator([5, 8], [5, 8, 30, 50])
output will be 5 8 5 8 30 50