TypeError: 'int' object is not iterable

前端 未结 4 587
[愿得一人]
[愿得一人] 2021-01-29 16:21

I am trying to have a program look inside multiple lists to see if there are multiple integers in those lists. I received an answer on a previous question I asked to accomplish

4条回答
  •  野性不改
    2021-01-29 16:34

    The statement for n in numbers in this code is causing the problem

    def all_num_in_list(d, numbers):      
        for n in numbers:          
            if n not in d:              
                return False      
        return True
    

    The Partial Traceback is

    if n not in d
    def all_num_in_list(d, numbers):
    def all_num_in_any_list(lists, numbers):
    if all_num_in_any_list([2, 3, 4, 5, 6, 7, 8, 9], [row, box1, all(row[row.index(0)])]):        
    TypeError: 'int' object is not iterable
    

    So in function all_num_in_any_list you are already iterating for d in lists over the list lists to get integers which is passed to all_num_in_list. But here while trying to compare n with an atom d, is where the Error Happened.

    Think Over?

    Did you intend to do an integer comparition like n != d instead of if n not in d .

    Note::: Next Time please post the Complete Traceback

提交回复
热议问题