If you replace the nested for loops (plain or in a generator expression) with a call to itertools.product, the reader will immediately see the intent.
itertools.product
result = product(first, second)
Most of the times, this carthesian product is only iterated over and above example will do. If it needs to be stored, you'll need a tuple:
result = [tuple(*p) for p in product(first, second, third) ]
Notice how each added level requires only an added argument to product.
product
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
If you replace the nested for loops (plain or in a generator expression) with a call to
itertools.product
, the reader will immediately see the intent.Most of the times, this carthesian product is only iterated over and above example will do. If it needs to be stored, you'll need a tuple:
Notice how each added level requires only an added argument to
product
.