Algorithm Efficiency In Python