The method of insert doesn't work with nltk texts: AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert'
Token Type
typetoken at gmail.com
Sun Sep 2 05:39:15 EDT 2012
I wrote codes to add 'like' at the end of every 3 word in a nltk text as follows:
>>> text = nltk.corpus.brown.words(categories = 'news')
>>> def hedge(text):
for i in range(3,len(text),4):
new_text = text.insert(i, 'like')
return new_text[:50]
>>> hedge(text)
Traceback (most recent call last):
File "<pyshell#77>", line 1, in <module>
hedge(text)
File "<pyshell#76>", line 3, in hedge
new_text = text.insert(i, 'like')
AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert'
Isn't text in the brown corpus above a list? why doesn't it has attribute 'insert'?
Thanks much for your hints.
More information about the Python-list
mailing list