Return the strings matching regex whose length is in Ns.

def generate(regex, Ns):
    "Return the strings matching regex whose length is in Ns."
    return sorted(regex_parse(regex)[0](Ns),
                  key=lambda s: (len(s), s))