-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
  • 884
  • 2
  • 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
  • 105,000
  • 18
  • 159
  • 188