Dec-17-2020, 08:33 PM
(Dec-17-2020, 07:02 PM)muzikman Wrote: I adjusted it according to "bowlofred" without the "product" function. What does this function do anyway?
You can always look it up at the official documentation site.
Product takes some number of iterables (your lists) and makes every combination of one of each of the iterables. Example:
>>> from itertools import product >>> list(product([1,2,3], [10,20,30])) [(1, 10), (1, 20), (1, 30), (2, 10), (2, 20), (2, 30), (3, 10), (3, 20), (3, 30)]You could do the same with some for loops, but product handles arbitrary numbers of them without having to change the code (like going from 2 columns to 3 columns).
>>> list(product([1,2,3], [10,20,30], ["A", "B", "C"])) [(1, 10, 'A'), (1, 10, 'B'), (1, 10, 'C'), (1, 20, 'A'), (1, 20, 'B'), (1, 20, 'C'), (1, 30, 'A'), (1, 30, 'B'), (1, 30, 'C'), (2, 10, 'A'), (2, 10, 'B'), (2, 10, 'C'), (2, 20, 'A'), (2, 20, 'B'), (2, 20, 'C'), (2, 30, 'A'), (2, 30, 'B'), (2, 30, 'C'), (3, 10, 'A'), (3, 10, 'B'), (3, 10, 'C'), (3, 20, 'A'), (3, 20, 'B'), (3, 20, 'C'), (3, 30, 'A'), (3, 30, 'B'), (3, 30, 'C')]