Skip to content

Commit d2cdf28

Browse files
committed
Create 0004.py
1 parent 911eaa5 commit d2cdf28

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Liez-python-code/0004/0004.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# coding = utf-8
2+
__author__= 'liez'
3+
4+
import re
5+
def num(path):
6+
with open(path, 'r') as file:
7+
data=file.read()
8+
print(data)
9+
words=re.compile('[a-zA-Z0-9]+') #compile好像是必须用的,用来格式转换什么的,然后才能进行匹配之类的操作
10+
dict={}
11+
12+
for x in words.findall(data):
13+
if x not in dict:
14+
dict[x]=1
15+
else:
16+
dict[x]+=1
17+
18+
print(dict)
19+
20+
num('liez.txt')

0 commit comments

Comments
 (0)