VMware ESX vCenter Linux windows CCNA 忍者ブログ

IT号 着地号 いろいろ号

 ITに関しての調べ物です。バージョンや出展はつど記事に記載予定です。

カレンダー
05 2025/06 07
S M T W T F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
リンク
カテゴリー
かぶりもの
最新CM
[06/07 gay]
[02/16 gay]
[02/12 ヴィトン セカンドバッグ スーパーコピー ヴィトン]
[09/30 vente boutique canada goose paris]
[09/28 canada goose belgique]
最新記事
プロフィール
HN:
ESXi
性別:
非公開
バーコード
RSS
ブログ内検索
アーカイブ
最古記事
(01/14)
(01/20)
(01/20)
(01/26)
(01/26)
忍者アナライズ

Pythonで英単語の出現回数を数える場合

# 単語の出現回数をカウント
text = """
Keep on asking, and it will be given you:
Keep on seeking, you will find;
Keep on knocking, and it will be opend to you;
for everyone asking receives, and everyone seeking finds,
and to everyone knocking, it will be opend.
"""

# 単語を区切る
text = text.replace(";","") # ;を削除
text = text.replace(",","") # ,を削除
text = text.replace(".","") # .を削除
words = text.split() # 空白で区切ってリスト型を作成

# 単語を数える
counter = {} # counterという空の辞書型を作成
for w in words:
ws = w.lower() # 小文字に変換
if ws in counter: # もし辞書型にすでにキーがあれば値を1つ追加
counter[ws] += 1
else:
counter[ws] = 1 # もし辞書型にキーがなければ、値を1としてキーも登録

# 結果を表示。3回以上のものだけを表示
for k,v in sorted(counter.items()): # counterのキーをアルファベット順として範囲に指定
if v >= 3:
print(k, v)

拍手[0回]

PR
2017.04.15 (Sat)
Category[Python]
Comment(0)

コメント

この記事にコメントする
Name:
Mail:
URL:
Title:
Comment:
Password:
  Vodafone絵文字 i-mode絵文字 Ezweb絵文字

Copyright © ESXi All Right Reserved.
Powered by Ninja Blog.
Template-Designed by ガスボンベ.