Search code examples
pythonformatpython-itertools

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

  • print(*i) should do the trick.

    Explanation : the * unpack items from an iterable, so it is equivalent to : print(i[0],i[1],i[2])