Question

I have a list of dictionaries when I tried to put many values from the list I got this error:

ErrorType 'builtin_function_or_method' object is not iterable

this is my function:

def chooseOneServer():

     i=0
     for item in data:
         for key,value in item.items :
             if key == '1' :
                 servers = (
                        ('i',value), 

               ) 
                i +=1  
    return servers 


data =[{'1': value1.1,... },{'1':value2.1,...}]
Was it helpful?

Solution

I think the problem lies in this line:

for key,value in item.items:

dict.items() is a method, so item.items will give you the actual method (you then try to iterate over this method, hence the error). Instead, you want to call that method and get the result, so you'll need parentheses:

for key,value in item.items():
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top