Skip to Content
プログラミング文体練習 ―Pythonで学ぶ40のプログラミングスタイル
book

プログラミング文体練習 ―Pythonで学ぶ40のプログラミングスタイル

by Cristina Videira Lopes, 菊池 彰
June 2023
Intermediate to advanced content levelIntermediate to advanced
316 pages
4h 31m
Japanese
O'Reilly Japan, Inc.
Content preview from プログラミング文体練習 ―Pythonで学ぶ40のプログラミングスタイル

4章一枚岩――モノリスMonolithic

制約

  • 名前付き抽象化機能を使用しない。
  • ライブラリをほとんど使用しない、または全く使用しない。

プログラム

 1 #!/usr/bin/env python
 2 import sys, string
 3
 4 # [単語,頻度]の大域的リスト
 5 word_freqs = []
 6 # ストップワードのリスト
 7 with open('../stop_words.txt') as f:
 8     stop_words = f.read().split(',')
 9 stop_words.extend(list(string.ascii_lowercase))
10
11 # ファイル内の行単位で繰り返し
12 for line in open(sys.argv[1]):
13     start_char = None
14     i = 0
15     for c in line:
16         if start_char is None:
17             if c.isalnum():
18                 # 単語の始まり
19                 start_char = i
20         else:
21             if not c.isalnum():
22                 # 単語の終わり。見つけた単語の処理を行う
23                 found = False
24                 word = line[start_char:i].lower()
25                 # ストップワードに該当しない単語を処理する
26 if word not in stop_words: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

SQLではじめるデータ分析 ―クエリで行う前処理、時系列解析、コホート分析、テキスト分析、異常検知

SQLではじめるデータ分析 ―クエリで行う前処理、時系列解析、コホート分析、テキスト分析、異常検知

Cathy Tanimura, 大橋 真也, 嶋田 健志, 木下 哲也
レガシーコードからの脱却 ―ソフトウェアの寿命を延ばし価値を高める9つのプラクティス

レガシーコードからの脱却 ―ソフトウェアの寿命を延ばし価値を高める9つのプラクティス

David Scott Bernstein, 吉羽 龍太郎, 永瀬 美穂, 原田 騎郎, 有野 雅士
プログラミングRust 第2版

プログラミングRust 第2版

Jim Blandy, Jason Orendorff, Leonora F. S. Tindall, 中田 秀基

Publisher Resources

ISBN: 9784814400225Other