The task before:
A prime factor is a factor that is a prime number. Prime numbers are numbers that have exactly two distinct positive divisors: 1 and the number itself. For example, the first six prime numbers are 2, 3, 5, 7, 11, and 13.
The function prime_factors should take an integer as input. The integer will always be greater than 1.
def prime_factors(n):
divider = lambda x: next((i for i in range(2, x) if x % i == 0), -1)
return ([] if n == 1 else [n]) if divider(n) == -1 else ([divider(n)] + prime_factors(n // divider(n)))
import codewars_test as test
import solution # or from solution import example
@test.describe("Prime factors test")
def test_case():
test.assert_equals(prime_factors(100), [2, 2, 5, 5])
test.assert_equals(prime_factors(37), [37])
test.assert_equals(prime_factors(18), [2, 3, 3])