Guest User

Untitled

a guest
Aug 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. # the reading part
  2.  
  3. try:
  4.     inFile = open("unsortedfruits.txt", 'r')
  5.  
  6. except IOError:
  7.     print 'Failed opening unsortedfruits.txt to read'
  8.  
  9. fList = []
  10.  
  11. for unsortedfruits in inFile:
  12.     fList.append(unsortedfruits)
  13.    
  14. fList.sort()
  15.  
  16. inFile.close()
  17.  
  18. # the writing part
  19.  
  20. try:
  21.     outFile = open("sortedfruits.txt", 'w')
  22.  
  23. except IOError:
  24.     print 'Failed writing into sortedfruits.txt'
  25.    
  26. outFile.writelines(fList)
  27.  
  28. outFile.close()
Add Comment
Please, Sign In to add comment