As such the bulk of my work ends up as procedures. Witness the following...

```
def is_prime(x):
if x < 2: return False
if x > 2:
for i in range(2, int(x ** 0.5) + 1, 2):
if x % i == 0: return False
return True
def primes_to_n(n):
if n < 2: return
primes = [2]
primes += [x for x in range(3, n+1, 2) if is_prime(x)]
return primes
def prime_factors(n):
factors = primes_to_n(int(n / 2) + 1)
freq = {}
for i in range(len(factors)):
f = factors[i]
freq[f] = 0
while True:
if n % f == 0:
n /= f
freq[f] += 1
else: break
return { k: freq[k] for k in freq if freq[k] > 0}
def prime_factor_sum(n):
freq = prime_factors(n)
return sum([k * freq[k] for k in freq])
```

```
print (1089, prime_factors(1089))
print (prime_factor_sum(1089))
print (28, prime_factors(28))
print (prime_factor_sum(28))
```

I suspect very weak on optimization, my greatest weakness. Would it were this (optimization) would sink in. Any takers?