The problem here is that you are trying to access an NLTK corpus
object as if it was a list object. However, you can convert it to a
list like this:
text = list(nltk.corpus.brown.words(categories = 'news'))
-Steven Bird
On 2 September 2012 14:32, typetoken <
type...@gmail.com> wrote:
> I want to add 'like' at the end of every other 3 words in a text. Then I
> try to use insert as follows. However, it told me that "AttributeError:
> 'ConcatenatedCorpusView' object has no attribute 'insert'". Quite puzzled?
> Isn't text a list here? If it is a list, why doesn't not insert work here?
>
>>>> text = nltk.corpus.brown.words(categories = 'news')
>>>> def hedge(text):
> for i in range(0, len(text),3):
> text.insert(i,'like')
>
>>>> hedge(text)
>
> Traceback (most recent call last):
> File "<pyshell#33>", line 1, in <module>
> hedge(text)
> File "<pyshell#32>", line 3, in hedge
> text.insert(i,'like')
> AttributeError: 'ConcatenatedCorpusView' object has no attribute 'insert'
>
>
> Further more, I test the function of insert. It did work as follows:
>
>>>> text = ['The', 'Fulton', 'County', 'Grand']
>>>> text.insert(3,'like')
>>>> text
> ['The', 'Fulton', 'County', 'like', 'Grand']
>>>>
>
> Thanks for your instructions!
>
> --
>
>