Python basics------How to count the frequency of a list element

Source: Internet
Author: User
How to count the frequency of a list element two requirements: 1, statistics a random sequence [1,2,3,4,5,6 ...] The number of occurrences in the first three of the elements and the number of times 2, a piece of English article in the number of times before the first 10 words two methods:

1, the normal for loop, combined with the front of the Python foundation-------How to filter the contents of the data in a list dictionary collection based on criteria

2, counter method of self-brought library collections

Solution requirements One, two methods one:

Mister into a random list, get the largest element by method one

Get most elements

Focus on the second approach

1, first import

 from Import Counter

2, A is the original list

3, get the first three frequency

Solution Requirement Two:

Statistics test the frequency of the occurrence of English words in this article

1, open, assign a value to F

2, Split F, by non-alphanumeric, generate a longer list

3, Statistics

Python basics------How to count the frequency of a list element

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.