New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FreqDist.keys() produces map object (dictionary?) and not list #390
Comments
Do you use Python 3.x? In Python 3.x dict.keys() method returns iterator; while porting to Python 3.x I decided to prefer idiomatic behavior over backwards compatibility in such cases. NLTK 3 is still in alpha so we could revert this decision - if you have some arguments in favor of keys returning list they are welcome. Also, in Python you usually write
|
If you want to follow the book it is better to install Python 2.7 because the book is not updated for NLTK3 / Python 3.x yet. |
My suggestion is to keep the current behavior and update the docstrings. (The same also holds for .values()) |
Hi kmike. Thanks for the information. I figured it was something like that. I have no problem with the new behavior. |
@sonofmun I like your approach 👍 But be ready that many pre-trained models won't work (I think including @heatherleaf Do you have ideas how to fix those docstrings? "Return list in Python 2.x and iterable in Python 3.x" is a bit cumbersome. |
No, I think that's fine. But perhaps "iterator" is better than "iterable", since that's what the documentation for map() in py3 says. "Returns a list in Python 2.x, and an iterator in Python 3.x" |
the documentation in |
Yes, I think this should be reopened per previous comment. The main use of FreqDist seems to me to be to get stuff in frequency order, but that's not what happens in Python3, so imho this is quite broken. |
FreqDist in NLTK3 is a wrapper for collections.Counter; Counter provides @undertherain docs at googlecode are very old, they are from 2011. More up-to-date docs can be found on http://nltk.org website. |
Oh, I see! I just got confused by the documentation linked by |
After importing NLTK and * from nltk.book, I run the following code and get the following results:
The help for FreqDist says that keys(self) should produce a list of the keys but it appears that it produces another dictionary.
I can get a list of the keys by typing:
Is the behavior of the code as it should be and the help simply not updated? Or is this a problem with the code?
The text was updated successfully, but these errors were encountered: