Skip to content

Commit bd2fecf

Browse files
committed
commit0004
1 parent b4e216e commit bd2fecf

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

darcycool/0004/count_words.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# 第 0004 题: 任一个英文的纯文本文件,统计其中的单词出现的个数。
3+
import re
4+
5+
file = open('words.txt', 'r')
6+
str = file.read()
7+
8+
reObj = re.compile('\b?(\w+)\b?')
9+
words = reObj.findall(str)
10+
11+
wordDict = dict()
12+
13+
for word in words:
14+
if word.lower() in wordDict:
15+
wordDict[word.lower()] += 1
16+
else:
17+
wordDict[word.lower()] = 1
18+
19+
for key, value in wordDict.items():
20+
print('%s: %s' % (key, value))

darcycool/0004/words.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The amount of stupidity in this story warrants that this is going to be somewhat long, so I start at the end: as the title says, an 18 year old guy was arrested two days ago for 'hacking' the new Budapest public transport e-Ticket system a week before, even though he immediately reported the vulnerability he found.

0 commit comments

Comments
 (0)