'Formatting print from itertools product
I am trying to print a list of every combination of a certain set of characters, I am using Product from itertools to do that. I have code that works for the printing of every set of characters, but, the formatting is not what i want.
Example of working code with wrong format:
from itertools import product
comb = product([1, "a", "."], repeat=3)
for i in comb:
print(i)
The output of the code has the characters ( ' , ) which I don't want. If someone can help me get an output of what the combonation would be by its self without these characters I would really appreciate that.
Solution 1:[1]
You can think of comb as being a list of all combinations as tuples.
So just unpack each item while iterating, then you can also handle seperatly:
for (v0, v1, v2) in comb:
print(v0, v1, v2)
Result:
1 1 1
1 1 a
1 1 .
1 a 1
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ivvija |
