···11import math
22+import operator
23from functools import total_ordering
44+55+66+LETTERS = [x for x in 'abcdefghijklmnopqrstuvwxyz']
77+VOWELS = {'a', 'e', 'i', 'o', 'u'}
88+CONSONANTS = set(x for x in LETTERS if x not in VOWELS)
99+1010+1111+def mul(lst):
1212+ """Like sum(), but for multiplication."""
1313+ return reduce(operator.mul, lst, 1)
1414+1515+1616+def factors(n):
1717+ """Returns the factors of n."""
1818+ return sorted(
1919+ x for tup in (
2020+ [i, n//i] for i in range(1, int(n**0.5) + 1)
2121+ if n % i == 0)
2222+ for x in tup)
2323+2424+2525+def primes(n):
2626+ """Returns the sorted list of primes in the range [2, n]"""
2727+ limit = n + 1
2828+ not_prime = set()
2929+ primes = []
3030+3131+ for i in range(2, limit):
3232+ if i in not_prime:
3333+ continue
3434+3535+ for f in range(i*2, limit, i):
3636+ not_prime.add(f)
3737+3838+ primes.append(i)
3939+4040+ return primes
341442543@total_ordering