1

I want to take a list and use enumerate to easily get the index and value of each element in the list. For some reason it keeps giving me the same error. I'm pretty new to Python, but not remotely new to coding. I would appreciate any insight.Ultimately, I'm calculating a heuristic for a hill climbing algorithm. But I'd like to handle the rest on my own and this is the only part that is giving me trouble right now.

def getHeuristic(state, graph):
    heur = 0
    for c, item in enumerate(state):
        print(item)
        vert = graph[item]
        for i in vert:
            if i in state:
                if i >= c:
                    heur += vert[i]
        return heur

And this is the error:

line 32, in getHeuristic
   for c, item in enumerate(state):
TypeError: 'int' object is not iterable

0 Answers0