I pass with Python3 (a)--dict and Collections.orderreddict encounter

Source: Internet
Author: User

Recently I have been on the Python Data analysis of the code (the book is based on Python2, small white I use the python3), so I next time how much some changes.

This is the NLTK frequency analysis of the 9.4 in the question about Dict_key.

The source code is this:

Operation Error:

Check the subscriptable, this link explained is still relatively clear. To put it simply, Dict_key no longer contains scriptable objects, such as List,tuple.

After a few attempts to fail, want to skip here, but the frequency of the analysis with a lot of the back, had to bite the bullet! Google half a day, found it (Ps:stackoverflow is still quite good).

That means adding a list. However, in this case, it is easy to remove the value of the highest-frequency item, but the corresponding key should not be found if the order is scrambled. So, continue to look for solutions. Thanks to the great God in the group to help, learned that there is a fixed dictionary order method--collections. Orderreddict. Refer to this blog post for specific use.

With this, you start to work, work goal-find out the number of words in the scrambled dictionary {' keyword ': ' Number '} and the number of occurrences.

So, there is it:

Operation Result:

Finally, it was a success ... But it always feels like a detour--but at least I learned to collections. orderresdict--hope to have a hero see can give a better solution.

As for Python Data analysis, it's time to read it and summarize it here.

I pass with Python3 (a)--dict and Collections.orderreddict encounter

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.