← Back to challenges

Prime Factorization of an Integer

PythonHardmathnumbersalgorithmsloops

Instructions

Create a function that returns a list containing the prime factors of whatever integer is passed to it.

Examples

prime_factors(20) ➞ [2, 2, 5]

prime_factors(100) ➞ [2, 2, 5, 5]

prime_factors(8912234) ➞ [2, 47, 94811]

Notes

  • Implement your solution using trial division.
  • Your solution should not require recursion.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.