Some time ago I was trying to solve the same issue but using a new keyword "where", and I thought that new keyword is too much for just list comprehension filtering, so I've made it something like assignments in expresion, eg.
(x+y)**2 + (x-y)**2 where x=1, y=2
So for list comprehension I can write:
[stripped for line in lines if stripped where stripped=line.strip()]
result = map(f, objs) where f=lambda x: x.return_something()
it = iter(lines)
while len(line) > 4 where line=next(it, '').strip():
lambda x, y: (
0 if z == 0 else
1 if z > 0 else
-1) where z = x + y
lambda something: d where (d, _)=something, d['a']=1
I even implemented it:
and it works nicely. I was thinking to reuse "with [expr] as [var]" but I also don't like idea of context sensitive semantics, and I even thought that maybe someone, someday would want to write "content = fp.read() with open('foo.txt') as fp"...
The "where" keyword is from guards pattern in Haskell :)