Drkcore

13 07 2007 Python Tweet

pythonで単語の頻度をカウントするには

perlだと

for my $word (@word_list) {
  $count{$word}++;
}

とかできるのだけど、pythonだとループの内部で

if count.has_key(word):
    count[word] = count[word] + 1
else:
    count[word] = 1

とかやって、キーがあるのかないのか調べないといけないようだ。

もっとスマートなやり方あるような気もするんだが。

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021