Also, use xrange as it's faster than range even for short sequences.
Attach a file by drag & drop or click to upload