>>> text5.collocations()
Building collocations list
wanna chat; PART JOIN; MODE #14-19teens; JOIN PART; PART PART; cute.-ass MP3; MP3 player; JOIN JOIN; times .. .; ACTION watches; guys wanna; song lasts; last night; ACTION sits; -...)...- S.M.R.; Lime Player; Player 12%; dont know; lez gurls; long time
>>> len(set(text4))
9754
1-9 と 1-10 は同じテーマっぽいので一緒に扱う。 リストで作っておいて、join で繋げると楽(模範解答ではないかも)。
>>> mystring = ['my', 'string']
>>> ' '.join(mystring + mystring)
'my string my string'
>>> 'my string my string'.split()
['my', 'string', 'my', 'string']
リストを連結してから長さを計算した場合。 リストのそれぞれの長さを計算して足した場合。 どちらも同じになる。
文字列とみなして、一部分を切りとる(出力は、言語的に意味の無いものかもしれない)。 単語を取り出す(言語的に意味のあるまとまりを出力する)。
sent1[2] は、3番目の単語を取り出す。 sent1[2][2] は、3番目の単語の3文字目を取り出す。 他には、sent1[2][0:2] (3番目の単語の1-2文字目)など。
>>> sent1[2]
'Ishmael'
>>> sent1[2][2]
'h'
>>> sent1[2][0:2]
'Is'
index の第二引数に、検索開始位置を指定する。 もし検索した語が存在しない場合、ValueError: list.index(x): x not in list のようなメッセージが表示される。
>>> sent3.index('the',2)
5
>>> sent3.index('the',6)
8