← Back to challenges

String Factoring

PythonHardarraysstringsloopsconditions

Instructions

Given the complete factorization of a number, create a function that converts this list of factors to a string.

To illustrate: 24's complete factorization is [2, 2, 2, 3], which should be converted to "2^3 x 3".

Examples

string_factor([2, 2, 2, 3, 3]) ➞ "2^3 x 3^2"

string_factor([2, 7]) ➞ "2 x 7"

string_factor([2, 3, 3]) ➞ "2 x 3^2"

Notes

  • Factors should be joined with x (multiplication sign).
  • Multiple instances of the same factor should be exponentiated.
  • Factors raised to the 1 power should be left as is, i.e. write 7 instead of 7^1.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.