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

Join permutations with newline fails

From

from itertools import permutations
perms = ['\n'.join(p) for p in permutations(['mac', 'hi', 'ne'])]
print(set(perms))

I get

{'hi\nne\nmac', 'hi\nmac\nne', 'ne\nmac\nhi', 'mac\nhi\nne', 'ne\nhi\nmac', 'mac\nne\nhi'}

And if I try

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

from itertools import permutations
perms = [''.join(p) for p in permutations(['mac', 'hi', 'ne'])]
print(set(perms), sep='\n')

I get

{'macnehi', 'nehimac', 'nemachi', 'machine', 'hinemac', 'himacne'}

My desired output should look like

macnehi
nehimac
nemachi
machine
hinemac
himacne

I don’t know what I’m messing. I’m appreciate any hints.

>Solution :

Expand the set:

print(*set(perms), sep='\n')

Or, join it explicitly:

print('\n'.join(set(perms)))
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