| 1 | initial version |
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)
Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.