Код Использование кода all_factors
def reverse_factors(n, max_):
# Loops through numbers from 1 to max_ to check
# number of factors. Keeps the ones with the desired
# number of factors as determined by len(all_factors(x))
return [x for x in range(1, max_+1) if len(all_factors(x)) == n]
Тест
# Numbers with 4 factors up to 30
print(reverse_factors(4, 30))
Выход
[6, 8, 10, 14, 15, 21, 22, 26, 27]