Cecelia
Cecelia

Reputation: 1

'method' object is not sub scriptable in python

I am implementing Minimum Remaining Values of CSP in python.And I got some errors.

I run with python3 and also with python2 interpreter .

def select_unassigned_variable(assignments, csp):
    variables = [var for var in csp.nodes()
                     if var not in assignments.keys()]
    if not variables:
        return None
    return min(variables, key=(lambda var: (len(csp.nodes[var]['domain']))))

I got the error like:

return min(variables, key=(lambda var: (len(csp.nodes[var]['domain']))))
TypeError: 'method' object is not subscriptable

Upvotes: 0

Views: 161

Answers (1)

SuperStew
SuperStew

Reputation: 3054

change to something like

key=(lambda var: (len(csp.nodes()[var]['domain']))))

Upvotes: 1

Related Questions