forked from Show-Me-the-Code/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice4(2).py
More file actions
33 lines (30 loc) · 783 Bytes
/
practice4(2).py
File metadata and controls
33 lines (30 loc) · 783 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# -*- coding:utf-8 -*-
file = open('./English.txt','r')
s = set()
map = {}
allLines = file.readlines()
def pre(i):
if not i in s:
map[i] = 1
s.add(i)
else:
map[i] += 1
for eachLine in allLines:
alist = eachLine.split()
if alist != []:
for i in alist:
i = i.lower()
if i[-1] == '.' or i[-1] == ',' or i[-1] == "'" or i[-1] == '?' :
i = i[:-1]
if i == '':
continue
if '.' in i:
a = i.split('.')
for j in a:
pre(j)
continue
pre(i)
else:
pass
print s
print map