Optimizing Python Code For Efficiency