Python Inner Function Access Outer Variable Frequency