0

I want to create an iterator that returns progressively larger products of another iterator, i.e., return first the products with repeat=1, then repeat=2, and so on. In code, it would be:

infinite_product('AB')
-> ('A'), ('B'), ('AA'), ('AB'), ('BA'), ('BB'), ('AAA'), ('AAB'), ('ABA')...

The closest function described in itertools documentation is powerset(), which I was unable to adapt because the iterator is supposed to be infinite and using itertools.count() as the repeat argument is not possible (TypeError: 'itertools.count' object cannot be interpreted as an integer).

Is it possible to do something similar with itertools, without writing nested loops?

Giacomo
  • 300
  • 4
  • 8
  • 1
    Possible duplicate / related reading: [How to make a continuous alphabetic list python (from a-z then from aa, ab, ac etc)](https://stackoverflow.com/q/29351492/953482) – Kevin Jul 30 '19 at 19:44
  • Seems you'll have to nest somewhere if you are going to use itertools.product with successive values for the repeat parameter. – wwii Jul 30 '19 at 19:47

0 Answers0