fork download
  1. def dict_create(min_factor, max_factor):
  2. dict_resulted = {}
  3. for i in range(min_factor, max_factor + 1):
  4. for j in range(min_factor, max_factor + 1):
  5. num, list_of_factors = i * j, sorted([i, j])
  6. if num not in dict_resulted:
  7. dict_resulted[num] = [list_of_factors]
  8. else:
  9. if list_of_factors not in dict_resulted[num]:
  10. dict_resulted[num].append(list_of_factors)
  11. return dict_resulted
  12.  
  13.  
  14. def largest(min_factor, max_factor):
  15. if max_factor < min_factor:
  16. raise ValueError("min must be <= max")
  17. dict_operated = dict_create(min_factor, max_factor)
  18. for num in sorted(dict_operated, reverse = True):
  19. if str(num) == str(num)[::-1]:
  20. return tuple([num, dict_operated[num]])
  21.  
  22.  
  23. def smallest(min_factor, max_factor):
  24. if max_factor < min_factor:
  25. raise ValueError("min must be <= max")
  26. dict_operated = dict_create(min_factor, max_factor)
  27. for num in sorted(dict_operated):
  28. if str(num) == str(num)[::-1]:
  29. return tuple([num, dict_operated[num]])
  30.  
  31.  
  32. print(largest(10, 99))
  33. print()
  34. print(smallest(10, 99))
  35.  
Success #stdin #stdout 0.07s 66036KB
stdin
Standard input is empty
stdout
(9009, [[91, 99]])
()
(121, [[11, 11]])