In [1]:
import collections
In [2]:
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
return a
In [3]:
print(prime_factorize(1))
In [4]:
print(prime_factorize(36))
In [5]:
print(prime_factorize(840))
In [6]:
c = collections.Counter(prime_factorize(840))
print(c)
In [7]:
print(c.keys())
In [8]:
print(c.values())
In [9]:
print(c.items())
In [10]:
print(list(c.keys()))