Version of gen that doesn't use itertools.