f = open('C:/1.txt','r')
s = f.read()
u = s.decode('utf-8')
str = u.encode('utf-8')
str1 = u.encode('gbk')
str1 = u.encode('utf-16')
print(s,"\n\n\nafter change as:\n\n")
print(s.lower())
import re
import collections
print( collections.Counter( re.findall( '\w+' ,open( 'C:/1.txt' ).read( ) ) ) )
import collections
import re
patt = re.compile("\w+")
counter = collections.Counter(patt.findall(
open('C:/1.txt', 'rt').read()
))
for word, times in counter.most_common(20):
print (word, times)
counter_dict = dict(counter.most_common(0))
tobefind = 'hello'
print (tobefind, counter_dict.get(tobefind, 0))
count what word
import re
txt = open('C:/1.txt', 'rt').read()
print (len(re.findall("NBA", txt)))