# most_common_words.py
import sys
from collections import Counter
if __name__ == "__main__":
try:
num_words =
int(sys.argv[1])
except:
print("usage:
most_common_words.py num_words")
sys.exit(1)
counter =
Counter(word.lower() \
for line in sys.stdin
for word in
line.strip().split()
if word)
for word, count in
counter.most_common(num_words):
sys.stdout.write(str(count))
sys.stdout.write("\t")
sys.stdout.write(word)
sys.stdout.write("\n")
다음과 같이 실행하면됩니다.
C:\work>type the_bible.txt | python most_common_words.py 20
댓글 없음:
댓글 쓰기
참고: 블로그의 회원만 댓글을 작성할 수 있습니다.