Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import codecs
- import string
- PATH = '/home/famihug/python/'
- f1 = codecs.open(PATH + 'am', 'r', "utf-8")
- nguyen_am = f1.readline()
- kq = u''
- f = codecs.open(PATH + 'in', 'r', 'utf-8')
- table = string.maketrans( '', '', )
- d = {}
- #string = f.readline()
- for s in f:
- s = s.lower()
- ls = s.split(" ")
- for word in ls:
- for i in range(0,len(word)):
- if nguyen_am.__contains__(word[i]):
- removed_punc = u"".join(c for c in word[i:] if c not in string.punctuation)
- if d.has_key(removed_punc):
- d[removed_punc] += 1
- else:
- d[removed_punc] = 1
- kq += removed_punc
- kq += " "
- break;
- f2 = codecs.open(PATH + 'out', 'w', 'utf-8')
- f2.write(kq)
- for k in d.keys():
- f2.write(str(d[k]) + ":" + k + "\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement