Does python have a "temporary" or "very local" variable facility? I am looking for a one-liner and I want to keep my variable space tidy.
I would like to do something like this:
...a, b, and c populated as lists earlier in code...
using ix=getindex(): print(a[ix],b[ix],c[ix])
...now ix is no longer defined...
The variable ix would be undefined outside of the one line.
Perhaps this pseudo-code is more clear:
...a and b are populated lists earlier in code...
{ix=getindex(); answer = f(a[ix]) + g(b[ix])}
where ix does not exist outside of the bracket.
del ixwhen you don't need it anymore.{answer = f(a[getindex()]) + g(b[getindex()])}?getindex()might be inefficient.answer = (lambda ix=getindex(): f(a[ix]) + g(b[ix]))(). But please don't.ix=getindex(); ans=f(a[ix]) + g(b[ix]); del ix;does accomplish what I need. But if I would still like to know if there exists a variable localization facility.