Changed range to xrange and rewrote as a one-liner
Added docstring and changed spacing