Python Nested Function Set Outer Variable Frequency