With
Implement as a Generator
#!/usr/bin/python

from contextlib import contextmanager

def f_1(n):
    print 'Call f_1() ...';
    return map(lambda x: x*2, n);

def f_2(n):
    print 'Call f_2() ...';
    n[0] = 100;

@contextmanager
def change(n):
    n = f_1(n);
    try:
        yield n;
    finally:
        n = f_2(n);

l = range(4); # [0, 1, 2, 3]
with change(l) as n:
    print n; # [0, 2, 4, 6]
print n; # [100, 2, 4, 6]
		
  1. l = [0, 1, 2, 3]
  2. Call f_1, n = [0, 2, 4, 6]
  3. Call f_2, n = [100, 2, 4, 6]
  4. Leave with block
Reference