Python Generate Function Dynamically Allocate