Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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])

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading