Divisor game cheating aid
Style guide

You should code your Python to follow PEP (Python Enhancement Proposal) documents, and in particular, PEP8.

PEP8

Comparing your code to PEP8's standards shows quite a few violations.


You should have whitespace between your binary operators.





factors=[]
number=int(n)




Two blank lines after a declaration





from operator import mul
from math import sqrt, ceil

def next_prime_factor(n):




Comparison to None: instead of != None it should be is not None





x=filter(None, numbers) + [2] if filter(None, numbers) != None else [2]




Line too long: PEP8 has a maximum character count of 79 characters per line, this line has 82:




print 'The smallest number with more divisors than the inputted number is',ans,'.'




while 1 should be denoted as while True instead:



while 1:





Whitespace and naming

You have double indentation here:


while number &gt; 1:
            f=next_prime_factor(number)
            factors.append(f)
            number /= float(f)
            number=int(number)
            if number==1:break



You should avoid names like this:


numbers = range(3, max_n+1, 2)
half = (max_n)/2



Their purpose is a little confusing. Try to use more descriptive names that better describe what they are.

You should name your variables like snake_case:


primecounts





Unnecessary logic


div_count=reduce(mul,div_exps(pcount),1)
return div_count



You're defining a variable right before returning it, just return it directly.


for i in primes_list:
    primecounts.append(factors.count(i))
return v



You can use the list comprehension notation instead:

primecounts = [factors.count(i) for i in primes_list]



if div_count(end_num)&lt;=div_count(last_num):
    end_num*=min(div_count_factors)
else:
    break



When you have a block that looks like this:


if condition == true/false:
    doSomething()
else:
    endBlock #return, break, continue



When the block terminates in the else loop, you can reverse the conditions and reduce a layer of logic:


if condition != true/false:
    endBlock

doSomething()



So, you can simplify that above block down:

if div_count(end_num) &gt; div_count(last_num):
    break

end_num *= min(div_count_factors)


The code after the if is not needed: filter always returns a list, which is empty, if no elements remain. This results in identical behavior to the current code.


x=filter(None, numbers) + [2] if filter(None, numbers) != None else [2]