Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion pylab: TypeError: unhashable type: 'list'
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
John H. Li  
View profile  
 More options Sep 2 2012, 11:40 pm
From: "John H. Li" <typeto...@gmail.com>
Date: Mon, 3 Sep 2012 11:39:10 +0800
Local: Sun, Sep 2 2012 11:39 pm
Subject: Re: [nltk-users] pylab: TypeError: unhashable type: 'list'

Now the solution has been found:
For the previous codes, I replace y.extend(fdist[word[i:i+1]]) with
y.extend([fdist[word[i]]]).
Then it works. I come to realize the difference between y.extend('90') ,
y.extend(['90']),  y.extend(90) and y.extend([90]).

On Mon, Aug 27, 2012 at 1:21 AM, typetoken <typeto...@gmail.com> wrote:
> For the exercise 23 on page 76, or  http://nltk.googlecode.com/**
> svn/trunk/doc/book/ch02.html<http://nltk.googlecode.com/svn/trunk/doc/book/ch02.html>
> ,
> I try the following codes but it pops up "TypeError: unhashable type:
> 'list"

> >>> import nltk
> >>> text = nltk.corpus.brown.words(**categories = 'news')
> >>> def zif(text):
> fdist = nltk.FreqDist(text)
> import pylab
> word = fdist.keys()
> x = []
> y = []
> index = []
> for i in range(0,len(set(text)),1):
> x.extend(word[i:i+1])
> y.extend(fdist[word[i:i+1]])
> index.extend('i+1')
> pylab.plot(index, y,'b')
> pylab.title('zipf law')
> pylab.xlabel('word rank')
> pylab.ylabel('word frequency')
> pylab.show()

> >>> zif(text)

> Traceback (most recent call last):
>   File "<pyshell#5>", line 1, in <module>
>     zif(text)
>   File "<pyshell#3>", line 10, in zif
>     y.extend(fdist[word[i:i+1]])
>   File "C:\Python27\lib\site-**packages\nltk\probability.py", line 495,
> in __getitem__
>     return self.get(sample, 0)
> TypeError: unhashable type: 'list'

> Any suggestions or solutions? thanks indeed.

> --
> You received this message because you are subscribed to the Google Groups
> "nltk-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/nltk-users/-/cBglUyK4yEcJ.
> To post to this group, send email to nltk-users@googlegroups.com.
> To unsubscribe from this group, send email to
> nltk-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/nltk-users?hl=en.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.