Ask Your Question

Revision history [back]

The condition in the list comprehension is like a lambda, and it doesn't like that you want to capture S in it.

You can avoid lambdas that capture other objects by using partial from functools:

def mytestproc(n,G,S):
    def f(S, v):
        return set(v) & S
    from functools import partial
    V = list(filter(partial(f, S), G.vertices()))
    return n*len(V)