下列Python代码用于寻找1~100之间的因数最多的数及其因数,程序本意是factor变量存储形如{6:[1,2,3,6],8:[1,2,4,8]},代码如下:
factor = {}
for i in range(1, 100):
for j in range(1, i+1):
if i % j == 0:
factor[i] = factor.get(i, []).append(j)
print(max(factor.items(), key = lambda x:len(x[1])))