Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #get the nth product of `lists`
- def product_by_idx(lists, n):
- result = []
- for seq in reversed(lists):
- n, x = divmod(n, len(seq))
- result.append(seq[x])
- return result[::-1]
- #find n such that product(lists, n) == target
- def idx_from_product(lists, target):
- n = 0
- for x, seq in zip(target, lists):
- n *= len(seq)
- n += seq.index(x)
- return n
- def product(lists, from_, to_):
- start = idx_from_product(lists, from_)
- end = idx_from_product(lists, to_)
- for n in range(start, 1+end):
- yield product_by_idx(lists, n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement