Yet again, I wasted too many minutes staring at and debugging my Python code due to the language’s funky variable scoping:
def relevant(xs, y): "Return elements in xs that are relevant to y." pairs = ((x, relevance(x,y)) for x in xs) return [(x,y) for x,y in pairs if y > 0]
In this case, the
y in the list comprehension modifies the binding used by the generator expression.
Follow me on Twitter for stuff far more interesting than what I blog.