Home  >  Article  >  Backend Development  >  How to count the number of elements in a list in python

How to count the number of elements in a list in python

silencement
silencementOriginal
2019-05-25 14:12:0623807browse

How to count the number of elements in a list in python

When using Python, the following scenarios usually occur:

How to count the number of elements in a list in python

For example, in the above list: 0 appears once , 1 appears 2 times, 2 appears 3 times, and 3 appears 2 times.

This article explains several methods for obtaining the number of occurrences of elements in Python.

There are many ways to get the number of occurrences of an element. Here I propose the following methods. In the following code, the parameters passed in are array = [1, 2, 3, 3, 2, 1 , 0, 2]

conuter() method

This method can quickly obtain the elements in the list The number of occurrences

How to count the number of elements in a list in python

count in the list, get the number of occurrences of each element

How to count the number of elements in a list in python

#Numpy fancy index , get the number of occurrences of each element

How to count the number of elements in a list in python

##

The above is the detailed content of How to count the number of elements in a list in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to parse a JSON fileNext article:How to parse a JSON file

Related articles

See more