LoginSignup
6
6

More than 5 years have passed since last update.

単語と単語idの対でできた辞書を簡単に作る

Posted at

自然言語処理でお馴染みの作業.
Pythonではもっと簡単らしい

words = ['apple', 'banana', 'cat']
Hash[words.each_with_index.map{|e, i|[e, i]}]
#=> {"apple"=>0, "banana"=>1, "cat"=>2}
6
6
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6