📄 wordcount.py
字号:
counter = {} # create empty directory
file = open("walrus.txt") # open file for input
while 1: # forever ...
line = file.readline() # read the next line
if line == "": # end of file?
break # yes: terminate loop
for w in line.split(): # for each word in the line
if counter.has_key(w): # have we seen this word before?
counter[w] += 1 # yes: add one to its count
else:
counter[w] = 1 # no: establish count of one
file.close() # tidy up
words = counter.keys() # extract a list of words found
words.sort() # sort the list
for w in words: # for each word in the list
print w, counter[w] # print the word and its count
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -