【python】自然言語処理100本ノックやってみた!【04本目】
演習問題が載っているサイトはこちらです!
04. 元素記号
"Hi He Lied Because Boron Could Not Oxidize Fluorine. New Nations Might Also Sign Peace Security Clause. Arthur King Can."という文を単語に分解し,1, 5, 6, 7, 8, 9, 15, 16, 19番目の単語は先頭の1文字,それ以外の単語は先頭に2文字を取り出し,取り出した文字列から単語の位置(先頭から何番目の単語か)への連想配列(辞書型もしくはマップ型)を作成せよ.
sentence="Hi He Lied Because Boron Could Not Oxidize Fluorine. New Nations Might Also Sign Peace Security Clause. Arthur King Can." s_list=sentence.replace(".","").split() associative_array={} for i in range(len(s_list)): if(i==0 or i==4 or i==5 or i==6 or i==7 or i==8 or i==14 or i==15 or i==18): associative_array[s_list[i][0]]=i else: associative_array[s_list[i][0:2]]=i print(associative_array)
05本目
第1章まとめ