Advertisement
2teez

Python for Informatics Exercise 8.4: Using a single For loop

Jul 10th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. # empty word list created
  2. wrd_list = []
  3.  
  4. filename = raw_input("Enter file name: ")
  5.  
  6. for line in  open(filename):
  7.     wrd_list.extend(line.split())
  8.  
  9. # used set built-in function to remove repeated string
  10. wrd_set = set(wrd_list)
  11.  
  12. # converted the set back to list using the list built-in function
  13. wrd_list = list(wrd_set)
  14.  
  15. wrd_list.sort() # sorting was done
  16. print wrd_list  # bingo!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement