Advertisement
FamiHug

tach_van.py

Feb 18th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import codecs
  4. import string
  5.  
  6. PATH = '/home/famihug/python/'
  7.  
  8.  
  9. f1 = codecs.open(PATH + 'am', 'r', "utf-8")
  10. nguyen_am = f1.readline()
  11.  
  12. kq = u''
  13. f = codecs.open(PATH + 'in', 'r', 'utf-8')
  14. table = string.maketrans( '', '', )
  15. d = {}
  16. #string = f.readline()
  17. for s in f:
  18.     s = s.lower()
  19.     ls = s.split(" ")
  20.     for word in ls:
  21.         for i in range(0,len(word)):
  22.             if nguyen_am.__contains__(word[i]):
  23.                 removed_punc = u"".join(c for c in word[i:] if c not in string.punctuation)
  24.                 if d.has_key(removed_punc):
  25.                     d[removed_punc] += 1
  26.                 else:
  27.                     d[removed_punc] = 1
  28.  
  29.                 kq += removed_punc
  30.                 kq += " "
  31.                 break;
  32.        
  33. f2 = codecs.open(PATH + 'out', 'w', 'utf-8')
  34. f2.write(kq)
  35. for k in d.keys():
  36.     f2.write(str(d[k]) + ":" + k  + "\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement