Mind-Blowing Python Tips and Tricks

A short list of Python tricks that make day-to-day code a little nicer. Nothing too magical, just handy stuff. 0 - Loop over a range of numbers Use range instead of xrange . In Python 3, the former creates an iterator-like object that produces values one at a time, which makes it much more efficient. nums = [ 0 , 2 , 34 , 55 , 32 ] for i in range ( nums ) : print i 1 - Looping backwards Just use…