Behold, my factors function!
Code:
def factors(n):
"""Returns an ordered list of factors of n"""
sqrtn = sqrt(n)
facts = not sqrtn%1 and [int(sqrtn)] or []
for i in range(int(ceil(sqrtn))-1, 0, -1):
if n%i == 0:
facts = [i] + facts + [n/i]
return facts
Anyhoo, it turns out that the problem is with the Spyder IDE; running the scripts from the command line results in much more similar timings. The first one still takes a couple of seconds longer for reasons I don't quite understand, but at least it's not several times as long.
Time for a new IDE I guess...