Skip to content

Commit

Permalink
added 0004
Browse files Browse the repository at this point in the history
  • Loading branch information
robot527 authored and cailurus committed Jan 3, 2015
1 parent bb83084 commit f6ff7c3
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
29 changes: 29 additions & 0 deletions robot527/0004/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
WHAT IS LINUX?

Linux is a clone of the operating system Unix, written from scratch by
Linus Torvalds with assistance from a loosely-knit team of hackers across
the Net. It aims towards POSIX and Single UNIX Specification compliance.

It has all the features you would expect in a modern fully-fledged Unix,
including true multitasking, virtual memory, shared libraries, demand
loading, shared copy-on-write executables, proper memory management,
and multistack networking including IPv4 and IPv6.

It is distributed under the GNU General Public License - see the
accompanying COPYING file for more details.

ON WHAT HARDWARE DOES IT RUN?

Although originally developed first for 32-bit x86-based PCs (386 or higher),
today Linux also runs on (at least) the Compaq Alpha AXP, Sun SPARC and
UltraSPARC, Motorola 68000, PowerPC, PowerPC64, ARM, Hitachi SuperH, Cell,
IBM S/390, MIPS, HP PA-RISC, Intel IA-64, DEC VAX, AMD x86-64, AXIS CRIS,
Xtensa, Tilera TILE, AVR32 and Renesas M32R architectures.

Linux is easily portable to most general-purpose 32- or 64-bit architectures
as long as they have a paged memory management unit (PMMU) and a port of the
GNU C compiler (gcc) (part of The GNU Compiler Collection, GCC). Linux has
also been ported to a number of architectures without a PMMU, although
functionality is then obviously somewhat limited.
Linux has also been ported to itself. You can now run the kernel as a
userspace application - this is called UserMode Linux (UML).
35 changes: 35 additions & 0 deletions robot527/0004/statistic_words.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#! usr/bin/python3
"""
第 0004 题:任一个英文的纯文本文件,统计其中的单词出现的个数。
"""

print('Please input a text file name which in the current working directory.')
print('Usage - example.txt')
file_name = input("@> ")

def deal_punctuation(the_string):
from string import punctuation as punc
punc_list = list(punc)
punc_list.remove('-')
ret_string = the_string
for each_punc in punc_list:
ret_string = ret_string.replace(each_punc, ' ')
ret_string = ret_string.replace(' -', ' ').replace('- ', ' ')
return ret_string

def stat(the_file):
try:
with open(the_file) as textfile:
word_list = []
for each_line in textfile:
temp = deal_punctuation(each_line)
word_list += temp.split()
print('This file has ', word_list.__len__(), ' words.')
word_set_list = sorted(set(word_list))
for each_word in word_set_list:
print(each_word + ' : ', word_list.count(each_word))
except IOError as err:
print('File error: ' + str(err))

if __name__ == '__main__':
stat(file_name)

0 comments on commit f6ff7c3

Please sign in to comment.