Skip to content

Commit 2dec509

Browse files
committed
complete 0006
1 parent ad29945 commit 2dec509

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

Jimmy66/0004/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@ The order is very important, if you write `[a-zA-Z]` after `|` , it will be igno
99

1010
What's more, in python use `'` in a string `\'` is necessary.
1111

12-
re.findall(r'[a-zA-Z]+(\'[a-zA-Z]+|\b)',string)
12+
re.findall(r'[a-zA-Z]+(\'[a-zA-Z]+|\b)',string)
13+
14+
15+
---
16+
17+
##Warning##
18+
19+
There are some mistake use this re in Python. It works well in Sublime. I will try to fix it in several days. Thank you!

Jimmy66/0006/0006.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import re
5+
6+
#返回英文单词列表
7+
def list1(string):
8+
words = re.findall(r'[a-zA-Z]+\b',string) #修改了正则表达式
9+
return words
10+
11+
#从文件中读取数据
12+
def file_read(filename):
13+
with open(filename,'r') as fp:
14+
article = fp.read()
15+
return article
16+
17+
#计算出出现最多的单词
18+
def most_word_number(word_list):
19+
str_dict = {}
20+
for item in word_list:
21+
if item in str_dict:
22+
str_dict[item] +=1
23+
else:
24+
str_dict[item] =1
25+
26+
str_dict = {str_dict[key]:key for key in str_dict}
27+
return (max(str_dict),str_dict[max(str_dict)])
28+
29+
30+
if __name__ == '__main__':
31+
string = file_read('GitHub.txt')
32+
words = list1(string)
33+
print (most_word_number(words))
34+

Jimmy66/0006/GitHub.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
GitHub
2+
3+
From Wikipedia, the free encyclopedia
4+
5+
GitHub is a web-based Git repository hosting service, which offers all of the distributed revision control and source code management (SCM) functionality of Git as well as adding its own features. Unlike Git, which is strictly a command-line tool, GitHub provides a web-based graphical interface and desktop as well as mobile integration. It also provides access control and several collaboration features such as wikis, task management, and bug tracking and feature requests for every project.[2]
6+
7+
GitHub offers both paid plans for private repositories and free accounts, which are usually used to host open-source software projects. As of 2014, GitHub reports having over 3.4 million users and with 16.7 million repositories[3] making it the largest code host in the world.[4]
8+

0 commit comments

Comments
 (0)