-1

I have this code:

import itertools
res = itertools.permutations('abcdefghijklmnopqrstuvwxyz',5) # 5 is the length of the result. 
for i in res: 
   print ''.join(i)

I need the result in stead of being printed print ''.join(i) to be saved in a .txt file.

I am not familiar with python. Thank you for your time!

Chris
  • 824
  • 1
  • 11
  • 22

1 Answers1

1

You can open the file in write mode and just use fileobject.write method to write your permutations to the file :

with open('file_name.txt','w') as f:
    res = itertools.permutations('abcdefghijklmnopqrstuvwxyz',5) # 5 is the length of the result. 
    for i in res: 
       f.write(''.join(i)+'\n') 
Mazdak
  • 100,514
  • 17
  • 155
  • 179