itertools.py 774 B

1234567891011121314151617181920212223242526272829303132333435
  1. """
  2. Thin wrappers around `itertools`.
  3. """
  4. import itertools
  5. from ..auto import tqdm as tqdm_auto
  6. __author__ = {"github.com/": ["casperdcl"]}
  7. __all__ = ['product']
  8. def product(*iterables, **tqdm_kwargs):
  9. """
  10. Equivalent of `itertools.product`.
  11. Parameters
  12. ----------
  13. tqdm_class : [default: tqdm.auto.tqdm].
  14. """
  15. kwargs = tqdm_kwargs.copy()
  16. tqdm_class = kwargs.pop("tqdm_class", tqdm_auto)
  17. try:
  18. lens = list(map(len, iterables))
  19. except TypeError:
  20. total = None
  21. else:
  22. total = 1
  23. for i in lens:
  24. total *= i
  25. kwargs.setdefault("total", total)
  26. with tqdm_class(**kwargs) as t:
  27. it = itertools.product(*iterables)
  28. for i in it:
  29. yield i
  30. t.update()