Skip to content

Commit 3ec12ca

Browse files
committed
added 0004
1 parent 3f8d7b7 commit 3ec12ca

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

robot527/0004/example.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
WHAT IS LINUX?
2+
3+
Linux is a clone of the operating system Unix, written from scratch by
4+
Linus Torvalds with assistance from a loosely-knit team of hackers across
5+
the Net. It aims towards POSIX and Single UNIX Specification compliance.
6+
7+
It has all the features you would expect in a modern fully-fledged Unix,
8+
including true multitasking, virtual memory, shared libraries, demand
9+
loading, shared copy-on-write executables, proper memory management,
10+
and multistack networking including IPv4 and IPv6.
11+
12+
It is distributed under the GNU General Public License - see the
13+
accompanying COPYING file for more details.
14+
15+
ON WHAT HARDWARE DOES IT RUN?
16+
17+
Although originally developed first for 32-bit x86-based PCs (386 or higher),
18+
today Linux also runs on (at least) the Compaq Alpha AXP, Sun SPARC and
19+
UltraSPARC, Motorola 68000, PowerPC, PowerPC64, ARM, Hitachi SuperH, Cell,
20+
IBM S/390, MIPS, HP PA-RISC, Intel IA-64, DEC VAX, AMD x86-64, AXIS CRIS,
21+
Xtensa, Tilera TILE, AVR32 and Renesas M32R architectures.
22+
23+
Linux is easily portable to most general-purpose 32- or 64-bit architectures
24+
as long as they have a paged memory management unit (PMMU) and a port of the
25+
GNU C compiler (gcc) (part of The GNU Compiler Collection, GCC). Linux has
26+
also been ported to a number of architectures without a PMMU, although
27+
functionality is then obviously somewhat limited.
28+
Linux has also been ported to itself. You can now run the kernel as a
29+
userspace application - this is called UserMode Linux (UML).

robot527/0004/statistic_words.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#! usr/bin/python3
2+
"""
3+
第 0004 题:任一个英文的纯文本文件,统计其中的单词出现的个数。
4+
"""
5+
6+
print('Please input a text file name which in the current working directory.')
7+
print('Usage - example.txt')
8+
file_name = input("@> ")
9+
10+
def deal_punctuation(the_string):
11+
from string import punctuation as punc
12+
punc_list = list(punc)
13+
punc_list.remove('-')
14+
ret_string = the_string
15+
for each_punc in punc_list:
16+
ret_string = ret_string.replace(each_punc, ' ')
17+
ret_string = ret_string.replace(' -', ' ').replace('- ', ' ')
18+
return ret_string
19+
20+
def stat(the_file):
21+
try:
22+
with open(the_file) as textfile:
23+
word_list = []
24+
for each_line in textfile:
25+
temp = deal_punctuation(each_line)
26+
word_list += temp.split()
27+
print('This file has ', word_list.__len__(), ' words.')
28+
word_set_list = sorted(set(word_list))
29+
for each_word in word_set_list:
30+
print(each_word + ' : ', word_list.count(each_word))
31+
except IOError as err:
32+
print('File error: ' + str(err))
33+
34+
if __name__ == '__main__':
35+
stat(file_name)

0 commit comments

Comments
 (0)