You are given two positive integers `a` and `b` (`a < b <= 20000`). Complete the function which returns a list of all those numbers in the interval `[a, b)` whose digits are made up of prime numbers (`2, 3, 5, 7`) but which are not primes themselves.
Be careful about your timing!
Good luck :)
from collections import defaultdict
from bisect import bisect_left

def gen_res(n):
    D = defaultdict(list)
    for q in range(2, n):
        if q not in D:
            D[q*q] = [q]
        else:
            if all(c in allowed for c in str(q)):
                yield q
            for p in D[q]: D[p+q].append(p)
            del D[q]
            
allowed = set("2357")
res = list(gen_res(20000))

def not_primes(a, b):
    return res[bisect_left(res, a):bisect_left(res, b)]
from collections import defaultdict
from bisect import bisect_left

def gen_res(n):
    D = defaultdict(list)
    for q in range(2, n):
        if q not in D:
            D[q*q] = [q]
        else:
            if all(c in allowed for c in str(q)):
                yield q
            for p in D[q]: D[p+q].append(p)
            del D[q]
            
allowed = set("2357")
res = list(gen_res(20000))

def not_primes(a, b):
    return res[bisect_left(res, a):bisect_left(res, b)]