With a profile in hand, you know what to speed up. The techniques come in a clear order of power. First, a better algorithm or data structure. Second, do less work: cache results, hoist work out of loops, stop early. Third, use the fast tools Python already has: built-ins, comprehensions, the standard library. Last, reduce memory and overhead. This lesson takes them in that order, each with a measurement.
More lessons in Complete Python Programming