def local_gen(): n = 0 def next(): nonlocal n n += 1 return n return next